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!
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:
oh sorry ! 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:
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
Change : $res = mysql_fetch_array($ch); while ( $v = $res ) { PHP: to while ( $v = mysql_fetch_assoc($ch) ) { PHP: