cbr_600rr Posted November 17, 2009 Share Posted November 17, 2009 Ok, I feel pretty stupid right now, I cannot get this code to work. I have a database with say 3 fields called id, field2, field3 values have already been stored in the fields The specific table only contains 1 row at anytime. How do I fetch the single row and pull out a value from say field2 and insert it into a variable? After making a successful connection to the DB, I have something like this,... $result = mysql_query('SELECT * FROM table1 WHERE id='1'); if($result){ echo "Successful"; }else { echo "ERROR";} $row = mysql_fetch_row($result); echo $row[0]; // should be equal to '1' (the first id number) echo $row[1]; // should be equal to value in field02 What am I doing wrong here? would it be easier to do something like this... $result = mysql_query('SELECT field2 FROM table1 WHERE id='1'); I appreciate the help guys Link to comment https://forums.phpfreaks.com/topic/181924-solved-pulling-single-row-from-database-and-inserting-specific-field-into-a-variable/ Share on other sites More sharing options...
mrMarcus Posted November 17, 2009 Share Posted November 17, 2009 your SQL syntax is wrong. you have one too many single-quotes. change your query to: $result = mysql_query('SELECT * FROM table1 WHERE id=1'); the rest should work as you have it. Link to comment https://forums.phpfreaks.com/topic/181924-solved-pulling-single-row-from-database-and-inserting-specific-field-into-a-variable/#findComment-959558 Share on other sites More sharing options...
cbr_600rr Posted November 17, 2009 Author Share Posted November 17, 2009 your SQL syntax is wrong. you have one too many single-quotes. change your query to: $result = mysql_query('SELECT * FROM table1 WHERE id=1'); the rest should work as you have it. Thanks for the help, it is working now! Link to comment https://forums.phpfreaks.com/topic/181924-solved-pulling-single-row-from-database-and-inserting-specific-field-into-a-variable/#findComment-959561 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.