Jump to content

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

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.