SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Dec 2000
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Everyone. I've been working through Kevin's tutorial for the last couple of days, and all is well except for this warning that I receive when I initially display all of the jokes in the database.

    Code:
    Warning: Undefined variable: submitjoke in C:/XITAMI/webpages/airbus/database.php on line 31
    It disappears when you add a joke, b/c submitjoke has been assigned a value. My question is - do you have to initialize this variable somewhere for the first time the page is loaded? I have followed Kevin's tutorial to a tee and the add and delete links work. Just wondering how to eliminate this warning message.

    This is the part of my .php file that the warning is referencing:

    Code:
      // If a joke has been submitted, add it to the database.  
      if ("SUBMIT" == $submitjoke) {  
        $sql = "INSERT INTO Jokes SET " . 
               "JokeText='$joketext', " .    
               "JokeDate=CURDATE()"; 
        if (mysql_query($sql)) {
          echo("<P>Your joke has been added.</P>");
        }
        else {  
          echo("<P>Error adding submitted joke: " . mysql_error() . "</P>");
        }
      }
    Thanks.
    <Edited by Kraems on 12-02-2000 at 07:29 PM>

  2. #2
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    change

    if ("SUBMIT" == $submitjoke)

    to

    if ($submitjoke == "SUBMIT")

    and it will go away. or just put

    if ($submitjoke)

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually nate it can be either way
    if ("submit" == $submit)

    or

    if ($submit == "submit")

    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    SitePoint Member
    Join Date
    Dec 2000
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the tips Nate and Freddy. I tried changing the order in the 'if' statement like you guys suggested but the warning is still present. I tried Nate's second suggestion too with no luck. Do you have any other ideas? I can display, add and delete from my database without any problems, but this warning message is a little annoying. Below is my .php file, if you can see any mistakes that might cause this warning, your help would be greatly appreciated.

    Code:
    <HEAD>
    <BODY>
    
    <?php
      // If the user wants to add a joke
      if (isset($addjoke)):
    ?>
    <FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>
    <P>Type your joke here:<BR><TEXTAREA NAME="joketext" ROWS=10 COLS=40 WRAP></TEXTAREA>
    <BR><INPUT TYPE=SUBMIT NAME="submitjoke" VALUE="SUBMIT">
    </FORM>
    
    <?php else:
      // Connect to the database server  
      $dbcnx = @mysql_connect("localhost","root","palmerston");  
      if (!$dbcnx) { 
        echo( "<P>Unable to connect to the database server at this time.</P>" );
        exit();  
      }
    
      // Select the jokes database  
      if (! @mysql_select_db("jokes") ) { 
        echo( "<P>Unable to locate the joke database at this time.</P>" ); 
        exit();  
      }
    
      // If a joke has been submitted, add it to the database.  
      if ($submitjoke) {  
        $sql = "INSERT INTO Jokes SET " . 
               "JokeText='$joketext', " .    
               "JokeDate=CURDATE()"; 
        if (mysql_query($sql)) {
          echo("<P>Your joke has been added.</P>");
        }
        else {  
          echo("<P>Error adding submitted joke: " . mysql_error() . "</P>");
        }
      }
    
      //If the joke has been deleted, remove it from the database.
      if (isset($deletejoke)) {
        $sql = "DELETE FROM Jokes WHERE ID=$deletejoke";
        if (mysql_query($sql)) {
          echo("<P>The joke has been deleted.</P>");
        }
        else {
          echo("<P>Error deleting joke: " . mysql_error() . "</P>");
        }
      }
    
      echo("<P> Here are all the jokes in our database: </P>");
     
      // Request the ID and text of all the jokes  
      $result = mysql_query("SELECT ID, JokeText FROM Jokes");  
      if (!$result) {    
        echo("<P>Error performing query: " . mysql_error() . "</P>");
        exit();
      }
    
      // Display the text of each joke in a paragraph
      while ( $row = mysql_fetch_array($result) ) {
        $jokeid=$row["ID"];
        $joketext=$row["JokeText"];
        echo("<P>$joketext <A HREF='$PHP_SELF?deletejoke=$jokeid'>Delete this joke.</A></P>");
      }
    
      // When clicked, this link will load this page
      // with the joke submission form displayed. 
      echo("<P><A HREF='$PHP_SELF?addjoke=1'>" . "Add a Joke!</A></P>");
    
    endif;
    ?>
    
    </BODY>
    </HTML>

  5. #5
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by freddydoesphp
    actually nate it can be either way
    if ("submit" == $submit)

    or

    if ($submit == "submit")

    Yea, I know that.

    BUT, I was thinking that with the second one it would figure out that $submit didn't exist and therefore couldn't equal "submit"

    and with the first one I was thinking it would produce a warning because it would try it compare $submit to submit and would think that $submit didn't exist or something.

    i dunno.

    anyways, i know that you can do it either way, i was just thinking that the other way might produce a warning, but i guess i am wrong...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •