Osorene Posted July 5, 2007 Share Posted July 5, 2007 In trying to get an id from a link to make a connection to my data base, for example if I have a link like this .../students/grades.php?ID=51 I need a connection to these record. The code I'm using is <?php $db = mysql_connect("localhost","campover","osorene"); mysql_select_db("campover_dbcv",$db); $requete = "SELECT * FROM cont_hist_05 WHERE ID=".$id; $result = mysql_query ($requete,$db); $article =mysql_fetch_object($result); mysql_free_result($result); ?> and I get this Notice: Undefined variable: id in c:\archivos de programa\easyphp1-8\www\public_html\prepa\conf_cont_hist3.php on line 16 Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in c:\archivos de programa\easyphp1-8\www\public_html\prepa\conf_cont_hist3.php on line 18 Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in c:\archivos de programa\easyphp1-8\www\public_html\prepa\conf_cont_hist3.php on line 18 Can I do something to solve this problem? Thank you in advance for all you people willing to help. Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 5, 2007 Share Posted July 5, 2007 need to use the get method $id=$_GET['id']; that get the id from url Quote Link to comment Share on other sites More sharing options...
trq Posted July 5, 2007 Share Posted July 5, 2007 <?php $db = mysql_connect("localhost","campover","osorene"); mysql_select_db("campover_dbcv",$db); if (isset($_GET['id'])) { $id = mysql_real_escape_string($_GET['id']); $requete = "SELECT * FROM cont_hist_05 WHERE ID=".$id; if ($result = mysql_query ($requete,$db)) { if (mysql_num_rows($result)) { $article = mysql_fetch_object($result); mysql_free_result($result); } } } ?> Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 5, 2007 Share Posted July 5, 2007 Osorene, might be an idea to remove usernames and passwords from scripts before posting them Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.