kev wood Posted June 2, 2008 Share Posted June 2, 2008 i am trying to store a number inside a db from a count. some data is being stored in the db but when i print out the variable instead of getting a number printed on the screen i get resource id #5. the code for setting the table up looks like this $sql="CREATE TABLE IF NOT EXISTS `email_count` ( `id` INT NOT NULL AUTO_INCREMENT, `sent_messages` INT, primary key (id) )"; mysql_query($sql) or die (mysql_error()); the code for updtaing and selecting the data looks like this mysql_query("UPDATE email_count SET sent_messages = $i") or die(mysql_error()); $query = "SELECT sent_messages FROM email_count"; $result=mysql_query($query)or die(mysql_error()); $sent_mail = $results; how can i get it to just display the number that is stored or just store the number. Link to comment https://forums.phpfreaks.com/topic/108349-solved-storing-data/ Share on other sites More sharing options...
fenway Posted June 2, 2008 Share Posted June 2, 2008 First, $results doesn't even exist. Second, $result in a RECORDSET... you need to grab the column you want, either with mysql_result() or mysql_fetch_assoc(). Link to comment https://forums.phpfreaks.com/topic/108349-solved-storing-data/#findComment-555514 Share on other sites More sharing options...
kev wood Posted June 2, 2008 Author Share Posted June 2, 2008 i changed the code to look like this but i still keep getting the same error. $query = "SELECT sent_messages FROM email_count"; $result=mysql_query($query)or die(mysql_error()); while($row=mysql_fetch_row($result, MYSQL_ASSOC)){ $send_mail =$row['sent_messages']or die(mysql_error()); } i have also tried it with array instead of row. i will now try the assoc Link to comment https://forums.phpfreaks.com/topic/108349-solved-storing-data/#findComment-555525 Share on other sites More sharing options...
kev wood Posted June 2, 2008 Author Share Posted June 2, 2008 no that didnt work either i am still getting the same error. the code i used for the assoc rty looks likw this $query = "SELECT sent_messages FROM email_count"; $result=mysql_query($query)or die(mysql_error()); while($row=mysql_fetch_assoc($result)){ $send_mail =$row['sent_messages']or die(mysql_error()); } Link to comment https://forums.phpfreaks.com/topic/108349-solved-storing-data/#findComment-555528 Share on other sites More sharing options...
kev wood Posted June 2, 2008 Author Share Posted June 2, 2008 the code i used looked like this and it works how i wanted it to selecting from the mysql db $query = "SELECT sent_messages FROM email_count"or die(mysql_error()); $results = mysql_query($query); $arr = mysql_fetch_array($results); $sent_mail = $arr[0]; updating the mysql db mysql_query("UPDATE email_count SET sent_messages = $i") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/108349-solved-storing-data/#findComment-555571 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.