Jump to content

[SOLVED] storing data


kev wood

Recommended Posts

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

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

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

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

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.