Jump to content

+1 to row in database


michytttt

Recommended Posts

Hello everyone,

 

I think what I am hoping to do should be fairly simple, although I a struggling getting the code correct.

 

I have a row in a database table called stats and another one called id - as well as a load of other rows which are irrelevant to what I am trying to achieve here.

 

What I am hoping to do is that when a specific id is selected from the database the stats number is what ever it was orginally +1.

 

Any suggestions?

 

The part of the code I am refering to is below:

 


$sql = "SELECT email, title FROM emails WHERE id='$id'";
$result = mysql_query($sql);while ($row = mysql_fetch_assoc($result)) {     
$to = $row['email'];
$job = $row['title'];
$row['stats'] == + 1; //this is the part that I know is completely wrong! everything else works fine. Just need this to say plus one onto the orginal number....

}

 

MOD EDIT: corrected BBCode tags . . .

Link to comment
Share on other sites

Oh right I see.

 

yes I currently have a form that is sent to a specific email address. The email address is selected from the database - depending on what the id is. This all works fine.

 

What I would like to now add is everytime an email is sent to one of the email address from the database the stats is +1 so that I can track how many emails have been sent to each address.

 

Link to comment
Share on other sites

It seems to be working! The database is adding one however I get this error now when I submit the form:

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/60/7908160/html/apply-for-job5.php on line 280

 

 

The code is as follows:

 

 

if($_SERVER['REQUEST_METHOD']== 'POST'){			
$sql2 = "UPDATE emails SET stats = (stats + 1) WHERE id='$id'"; 
$result2 = mysql_query($sql2);while ($row = mysql_fetch_assoc($result2)) {     
$stats = $row['stats'];

}

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.