doddsey_65 Posted November 23, 2009 Share Posted November 23, 2009 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 More sharing options...
premiso Posted November 23, 2009 Share Posted November 23, 2009 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. Link to comment https://forums.phpfreaks.com/topic/182586-another-problem-select-from-where/#findComment-963688 Share on other sites More sharing options...
Alex Posted November 23, 2009 Share Posted November 23, 2009 back ticks shouldn't even be used unless you're using reserved words. Link to comment https://forums.phpfreaks.com/topic/182586-another-problem-select-from-where/#findComment-963689 Share on other sites More sharing options...
robert_gsfame Posted November 23, 2009 Share Posted November 23, 2009 $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) ? should be tutorials WHERE id='1'"; Link to comment https://forums.phpfreaks.com/topic/182586-another-problem-select-from-where/#findComment-963690 Share on other sites More sharing options...
Alex Posted November 23, 2009 Share Posted November 23, 2009 If the field is of type INT it doesn't require quotes. Link to comment https://forums.phpfreaks.com/topic/182586-another-problem-select-from-where/#findComment-963693 Share on other sites More sharing options...
doddsey_65 Posted November 23, 2009 Author Share Posted November 23, 2009 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 Link to comment https://forums.phpfreaks.com/topic/182586-another-problem-select-from-where/#findComment-963694 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.