Jump to content

add a value + 1


cskiwi

Recommended Posts

hey, I have a shoutbox, and I want:

when someone makes a post to add a value +1

this is my code but it won't work

 

$naam = $_SESSION['username'];
// ... some code ...
$query = "SELECT * FROM users WHERE username='$naam' ";
$info =mysql_query($query) or die ("Reading Files Failed");
while ($gegeven = mysql_fetch_array($info))
{
$post=$gegeven->sb_post;
}

if(empty($post)) 
{
	$post1 = '1';
	$sql = "INSERT INTO users('sb_post') VALUES('$post1') WHERE username='$naam'";
	$result = mysql_query($sql1) or die ("Putting to 1 failled"); // this Error I always get
} 
else 
{
	$addpost = $post + 1;
	$sql2 = "update users set sb_post='$addpsot' WHERE username='$naam'";
	$result2 = mysql_query($sql2) or die ("+1 fail");
}

 

am I doing somthing rong?

Link to comment
https://forums.phpfreaks.com/topic/177080-add-a-value-1/
Share on other sites

 

sample of increment via 1 pal.

 

update whatever set whatever=whatever+1 where whatever='$whatever'

 

like this?:

if(empty($post)) 
{
	$sql = "INSERT INTO users ('sb_post') VALUES ('1') WHERE username = ('$naam')";
	$result = mysql_query($sql1) or die ("Putting to 1 failed");
} 
else 
{
	$sql2 = "update users set sb_post = ('$post+1') WHERE username = ('$naam')";
	$result2 = mysql_query($sql2) or die ("+1 Failed");
}

Link to comment
https://forums.phpfreaks.com/topic/177080-add-a-value-1/#findComment-933659
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.