Haha. This is wierd, after learning some PHP after my last thread, I decided to take that dudes challenge of making a news script. Well, it's working pretty well and stuff, I haven't implemented editing or deleting or anything like that yet, but anyways, here is my problem. From the point I am at my script works great. Except 2 things:

1) I get stupid errors like the following, yet the script works how it should:

Notice: Use of undefined constant hiddennews - assumed 'hiddennews' in c:\program files\apache group\apache\htdocs\black rain\news.php on line 41

(note I am using $_POST[string] for the variable)

and

2) How can I make my script work so that AFTER the form has been submitted, you can't submit the same one 2 times. For example, after I submit the form, I have a confirmation page that says "News has been submitted". If I hit the refresh button on that page, it will re-write the data that was in the form and duplicate itself into the database.


Any help would be appreciated!

    Hi,

    For your second question.. I am not sure wether this is the most elegant solution, but you could do a search.. you search hte database for exact matches on the data being inserted. If you have a hit, you do not need to insert the data, right?

    J.

      Hey Casper, long time no see....

      keep the code snips coming.. your explainiation was ok, but without the code to look at we can't do much here for you..

      Punchline: even when accessing array values, use quotes around all strings.

      $array['string'] not $array[string]

      Notice: Use of undefined constant hiddennews - assumed 'hiddennews' in c:\program files\apache group\apache\htdocs\black rain\news.php on line 41

      (note I am using $_POST[string] for the variable)

      Here is an example which replicates your problem

      <?php
      
      error_reporting(E_ALL);
      
      define('ConstA','a');
      
      $array = array( ConstA   => 'foo',
                      'ConstB' => 'bar' );
      
      echo '<br />';
      print $array[ConstA];
      
      echo '<br />';
      print $array[ConstB];
      
      echo '<br />';
      print_r($array);
      
      ?>
      

      html output:

      foo
      
      Notice: Use of undefined constant ConstB - assumed 'ConstB' in /usr/local/apache2/htdocs/test/const.php on line 16
      bar
      Array ( [a] => foo [ConstB] => bar )
      

      always wrap strings in quotes: '' or ""

      if you leave them out, php thinks you are referencing something you defined using the define() function.

      PHP searches and finds a ConstA, evaluates it to 'a', and uses it as the string 'a'

      $array[ConstA]
      $array['a']

      PHP searches and cannot find ConstB, so it assumes you messed up and tries 'ConstB', finds that works, and goes with it.

      $array[ConstB]
      $array['ConstB']

        Hmm, I'm thinking it is my database configuration because I uploaded the scripts to www.girderboot.com/riocard/news.php, and it doesn't do that constants thing. Well, maybe I have to define constants in php.ini or something. Thanks for the help.:p

          ok... see if this helps... the point is there is not supposed to be any constants... there is accidentally a constant there even though you didn't mean there to be

          when you type:

          $array[string]

          there is no quotes around 'string'

          so it thinks string is a constant

          $array['string']

          is the correct thing to type.

            Write a Reply...