Jump to content

[SOLVED] Problem when trying to get and id from url


Osorene

Recommended Posts

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.

<?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);
     }
   }
 }    

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.