Jump to content

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

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.