Jump to content

Another Problem (SELECT FROM WHERE)


doddsey_65

Recommended Posts

I want to select values from a db table and return them but when i echo the name field it brings a result from a dif table.

 

include('db.php');
    $db=mysql_connect($db_host,$db_user,$db_pass)
or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db($db_name,$db);

$query= "SELECT name, description, link, username, fullname FROM 'tutorials' WHERE id=1";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($res)

?
<p class="meta"><?php echo $row['username']; ?>

Link to comment
https://forums.phpfreaks.com/topic/182586-another-problem-select-from-where/
Share on other sites

You have an error in your SQL, you are using single quotes around tutorials it needs to be back ticks ( ` )

 

$query= "SELECT name, description, link, username, fullname FROM `tutorials` WHERE id=1";

 

See if that fixes your issue.

 

The most likely reason for your issue is that you used $row prior in the script and it was pulling that data and since the query error'ed out it did not set $row.  :)

that didn fix it, however i am using row in header.php which is included in every file but i thought it would be ok if i closed the connetion at the end of header.php? Is there a was around this? And yes the field type is INT

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.