SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Sep 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    undefined variable

    Hi,
    I am having trouble with some code:

    <html>

    <body>

    <?php

    $db = mysql_connect("localhost", "root");

    mysql_select_db("mydb",$db);

    if ($id) {

    $result = mysql_query("SELECT * FROM picture WHERE id=$id",$db);

    $myrow = mysql_fetch_array($result);

    printf("Name: %s\n<br>", $myrow["pic_name"]);

    printf("Title: %s\n<br>", $myrow["pic_title"]);

    printf("Description: %s\n<br>", $myrow["pic_description"]);

    printf("Price: %s\n<br>", $myrow["pic_price"]);

    } else {

    $result = mysql_query("SELECT * FROM picture",$db);

    if ($myrow = mysql_fetch_array($result)) {

    // display list if there are records to display

    do {

    printf("<a href=\"%s?id=%s\">%s %s</a><br>\n", $PHP_SELF, $myrow["id"], $myrow["pic_name"], $myrow["pic_title"]);

    } while ($myrow = mysql_fetch_array($result));

    } else {

    // no records to display

    echo "Sorry, no records were found!";

    }

    }

    ?>

    </body>
    </html>

    I keep getting this error message:

    Warning: Undefined variable: id in C:\Inetpub\wwwroot\phptest\querystring2.php on line 18

    Can anyone help?
    Thanks in advance,
    Dee

  2. #2
    Digital Warrior Renegade's Avatar
    Join Date
    Nov 2000
    Location
    Portland, OR
    Posts
    480
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Which line is line 18? Can you copy and paste the line of code that is giving you the trouble?

    Should I just start from the top and count? Cause I am not seeing an $id variable on line 18 if I do that
    --There's my 1.5 cents, now where is my change!?!?

  3. #3
    SitePoint Member
    Join Date
    Sep 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Renegade
    Which line is line 18? Can you copy and paste the line of code that is giving you the trouble?

    Should I just start from the top and count? Cause I am not seeing an $id variable on line 18 if I do that
    Hi Renegade,
    Sorry,I should have stated which line I meant. It's the line:

    if ($id) {

    Hope this makes it clearer!
    Thanx,
    Dee.

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Where is $id set, through the url? If thats the case, your php configuration probably does not include register globals. You may need to access it through $HTTP_GET_VARS['id'] or you can use extract($HTTP_GET_VARS); at the top of your script. Or turn register Globals to on inthe php.ini file if you have access.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i didn't know there was 2 topics on this! i told her (?) about the error_reporting in the other one.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  6. #6
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by DR_LaRRY_PEpPeR
    i didn't know there was 2 topics on this! i told her (?) about the error_reporting in the other one.
    That's true (http://www.sitepointforums.com/showt...threadid=35801), Dee try not to post repeated threads

    You may also want to read this

    http://www.sitepointforums.com/showt...threadid=35724

  7. #7
    SitePoint Member
    Join Date
    Sep 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Paul S


    That's true (http://www.sitepointforums.com/showt...threadid=35801), Dee try not to post repeated threads

    You may also want to read this

    http://www.sitepointforums.com/showt...threadid=35724

    Oops, sorry guys!
    I don't know how that happened (total newbie here!!).
    Thanks for your replies. I'm now going to delve back into my code and chech out your suggestions.
    Cheers!
    Dee


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
  •