Results 1 to 5 of 5

Thread: how to get URL parameter to show on result page

  1. #1
    Join Date
    Feb 2010
    Location
    los angeles
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to get URL parameter to show on result page

    *** i'm new and ***

    i can connect to my little mysql db just fine in php AND i can output all files (only 2 rows of data right now).

    problem: how do i grab the parameter in

    http://customtvis.com/caddetails_res...number=TVIS101

    result page code thus far (minus the private stuff):

    <?php

    //make connection
    mysql_connect ("", "",
    "") or die ('I cannot connect to the database because:' .mysql_error());
    mysql_select_db ("cad");

    //build query
    $query = mysql_query("SELECT * FROM cad");


    //display results
    while ($row = mysql_fetch_array($query)) {
    echo "<br /><h3>" .$row['number'].
    "<br />".$row['title'].
    "</h3><h4>".$row['category'].
    "<br />".$row['subtitle'].
    "</h4><br /> Downloads: ".$row['pdf'].
    "&nbsp;|&nbsp;".$row['dwg'].
    "<br />".$row['image'].
    "<br /> <br />".$row['description'].
    "<br /> <br /><em>Notes: ".$row['notes'].
    "</em><br />";}

    ?>

  2. #2
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    This is quite simple:
    PHP Code:
    $number =$_GET['number'];
    $query mysql_query("SELECT * FROM cad WHERE number=`$number`");
    //etc... 
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  3. #3
    Join Date
    Feb 2010
    Location
    los angeles
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Big thanks!

    thank you for the quick reply. at first this didn't work but then i realized the tick marks around the 2nd reference to 'number' seemed somewhat slanted so i changed them and it worked perfect.


  4. #4
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    Yeah sorry about that, little mistake... glad it works though...
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Since this is user input, you should make sure that there is no risk to the security of your database by the user inserting something like "; delete database" and ending the query with that

    $number = mysql_real_escape_string($_GET['number']);

    Use this every time you have user input directly in a query.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •