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
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
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
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
Share on other sites

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.