SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: $_GET Variable

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Port Sunlight
    Posts
    815
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_GET Variable

    Hi,

    If I have a link that opens up a page and passes the URL like so:

    Code:
    <a href="handmade_range.php?handmade_id=<?php echo $row_handmade['handmade_id']; ?>"><?php echo $row_handmade['handmade_name']; ?></a>
    And on that page it displays the right information.

    At the moment it just displays all the information that is associated with the first record in the database. So i'm assuming that I need to work on the query:

    Code:
    $handmade_sql = mysql_query("select * from handmade WHERE handmade_id = handmade_id") or die(mysql_error());
    $row_handmade = mysql_fetch_assoc($handmade_sql);
    This actually doesn't work, but I can't see why.

    Like I said earlier PHP isn't my best, but you should have seen me last year.

    Any help would be great.

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try

    WHERE handmade_id = $_GET[handmade_id]

  3. #3
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Port Sunlight
    Posts
    815
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I've tried this:

    Code:
    $id = $_GET['handmade_id'];
    
    # run the query to get the info from the database
    $handmade_sql = mysql_query("select * from handmade where handmade_id = $id") or die(mysql_error());
    $row_handmade = mysql_fetch_assoc($handmade_sql);

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if $id is not a number, you should quote it

    Code:
    $handmade_sql = mysql_query("select * from handmade where handmade_id = '$id'") or die(mysql_error());

  5. #5
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Port Sunlight
    Posts
    815
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok cheers,

    But its good practice to create variables at the start right? Rather than hardcoding.

  6. #6
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    -yes it generally is.

    i dont always use best practices when trying to show people what they need to do, im more concerned with getting the point across.

    but speaking of best practices, you _really_ should use mysql_real_escape_string() on any variable before you put it into an sql query.

    take a look here for how to use it
    http://us2.php.net/manual/en/functio...ape-string.php
    (theres a best practice example)


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
  •