Jump to content

SQL Update, HELP!!!


leeandrew

Recommended Posts

I have a code thats adds a number '1' to a field on submit in a form. I want to modify it so that if the field is not null it just adds another '1' onto the number.

 

e.g.

 

$query="UPDATE `database` SET `column` = '1' WHERE `name` = '$username';";

 

If the column contains the number 934, i want it to then read 935. Just add 1.

 

How can i do this by modifying the above code?

Link to comment
https://forums.phpfreaks.com/topic/98692-sql-update-help/
Share on other sites

Thanks, i figured it out myself accidentally by modifying the code i have shortly after i posted!

 

I have this code now:

 

	$query="UPDATE `voting_items` SET `top".$_POST['bookmark_number']."` = `top".$_POST['bookmark_number']."` + 1 WHERE `name` = 

'".$_POST['page']."';";
mysql_query($query);
$query2="UPDATE `pluserdata` SET `top".$_POST['bookmark_number']."` = '".$_POST['page']."' WHERE `userid` = '".$User->userid."';";
mysql_query($query2);
}

 

This adds a +1 to whatever number exists in the field. the second query bookmarks the name of the page in the users table of whoever has bookmarkd it.

 

So essentially a +1 goes into the page table field when someone bookmarks it, it allows me to check which pages are the most popular.

 

Problem is when a user overwrites it doesnt substract, so only works as an overall bookmark number and not current.

 

Any ideas on how to substract in the same query?

Link to comment
https://forums.phpfreaks.com/topic/98692-sql-update-help/#findComment-505097
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.