Jump to content

I can't retrive my data from table


Osorene

Recommended Posts

I´m connecting to a table in my database and receiving a notice instead of the expected information

 

I use this code to make the connection to the database (kindly corrected in this forum)

 

<?php 

  $db = mysql_connect("localhost"," * "," * "); 
  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);
      }
    }
  }    

?>

 

Then I try to call the information this way

 

<?php echo $article->b ?>

 

And this is what I get

 

Notice: Undefined variable: article in c:\archivos de programa\easyphp1-8\www\public_html\prepa\conf_cont_hist33.php on line 69

 

Thanks for all your help.

Link to comment
Share on other sites

<?php 

  $db = mysql_connect("localhost","campover","osorene"); 
  mysql_select_db("campover_dbcv",$db);   
  $article = "";

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

?>

 

Should solve the problem.

Link to comment
Share on other sites

Thank for your help, specially to frost110.

 

I don't receive the notice anymore but still I can't see the information, is something wrong in the way I'm trying to display it using the echo function? Is there another way?

 


I have some text here... then I place this to retrieve the information
from the table <?php echo $article->b ?> more text comes after 
and so on... 

 

Thanks again.

Link to comment
Share on other sites

Are you sure it is entering all of the if statements. Since you do not have any else statements to show an error message you are not sure. I would throw in some else statements so you can see where it is failing.

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.