page.php?id=1

Discussion in 'PHP' started by Isaac, Feb 16, 2008.

  1. #1
    Hey everyone,

    I've got my information in a mysql database. Each entry has a unique id number assigned to it. How can I make it so that when I got to mysite.com/page.php?id=1, that page shows the information for entry id 1 in the database? Kind of like how forums do profile.php?user=121 and it shows user 121's profile.

    Any help is appreciated!
     
    Isaac, Feb 16, 2008 IP
  2. James.Blant

    James.Blant Active Member

    Messages:
    250
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #2
    you should use a Dynamic SQL condition .
    sample :
    $id=$_GET['id'];
    $load = " SELECT * FROM Tblname WHERE id='$id'";
    $res = mysql_fetch_array(mysql_query($load));
    while ( $v = $res ) { 
      print " field 1 : ".$v['field1']." | field 2 : ".$v['field2'];
    } 
    
    PHP:
     
    James.Blant, Feb 16, 2008 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    nico_swd, Feb 16, 2008 IP
  4. Isaac

    Isaac Peon

    Messages:
    389
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks. Can you direct me to a good tutorial, or break that down a bit and explain it?
     
    Isaac, Feb 16, 2008 IP
  5. James.Blant

    James.Blant Active Member

    Messages:
    250
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #5
    oh sorry ! :p
    i forget injection . so you should check input(s) .
    here is new code :
    $id=$_GET['id'];
    if ( is _numeric($id)) { 
    $load = " SELECT * FROM Tblname WHERE id='$id'";
    $ch = mysql_query($load) ;
    if ( mysql_num_rows($ch) == "0" ) { die ("invalid input");} 
    $res = mysql_fetch_array($ch);
    while ( $v = $res ) {
      print " field 1 : ".$v['field1']." | field 2 : ".$v['field2'];
    }
    } else { print " Invalid input "; }
    PHP:
     
    James.Blant, Feb 16, 2008 IP
  6. Isaac

    Isaac Peon

    Messages:
    389
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I'm getting "Parse error: syntax error, unexpected T_STRING in /home/page/public_html/page.php on line 9"
    Line 9 is
    if ( is _numeric($id)) {
    
    Code (markup):
    EDIT: I fixed that, but now all it does is print the information over and over. See for yourself: http://www.gbx-emu.org/page.php?id=1
     
    Isaac, Feb 16, 2008 IP
  7. James.Blant

    James.Blant Active Member

    Messages:
    250
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #7
    remove space between "is" and "_numeric" .
    original command is : "is_numeric"
     
    James.Blant, Feb 16, 2008 IP
  8. decepti0n

    decepti0n Peon

    Messages:
    519
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Change :
    $res = mysql_fetch_array($ch);
    while ( $v = $res ) {
    PHP:
    to
    while ( $v = mysql_fetch_assoc($ch) ) {
    PHP:
     
    decepti0n, Feb 16, 2008 IP