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. Link to comment https://forums.phpfreaks.com/topic/58627-solved-problem-when-trying-to-get-and-id-from-url/ 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 Link to comment https://forums.phpfreaks.com/topic/58627-solved-problem-when-trying-to-get-and-id-from-url/#findComment-290825 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); } } } ?> Link to comment https://forums.phpfreaks.com/topic/58627-solved-problem-when-trying-to-get-and-id-from-url/#findComment-290827 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 Link to comment https://forums.phpfreaks.com/topic/58627-solved-problem-when-trying-to-get-and-id-from-url/#findComment-290829 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.