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.

Link to comment
Share on other sites

<?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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.