cskiwi Posted October 9, 2009 Share Posted October 9, 2009 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 More sharing options...
Zane Posted October 9, 2009 Share Posted October 9, 2009 What do you mean it won't work Link to comment https://forums.phpfreaks.com/topic/177080-add-a-value-1/#findComment-933654 Share on other sites More sharing options...
cskiwi Posted October 9, 2009 Author Share Posted October 9, 2009 I get an error (see code witch one) (in "if(empty($post))" is the error) Link to comment https://forums.phpfreaks.com/topic/177080-add-a-value-1/#findComment-933655 Share on other sites More sharing options...
Zane Posted October 9, 2009 Share Posted October 9, 2009 INSERT INTO users[NEED A SPACE]('sb_post') VALUES[NEED A SPACE]('$post1') WHERE username='$naam' Link to comment https://forums.phpfreaks.com/topic/177080-add-a-value-1/#findComment-933656 Share on other sites More sharing options...
redarrow Posted October 9, 2009 Share Posted October 9, 2009 sample of increment via 1 pal. update whatever set whatever=whatever+1 where whatever='$whatever' Link to comment https://forums.phpfreaks.com/topic/177080-add-a-value-1/#findComment-933657 Share on other sites More sharing options...
cskiwi Posted October 9, 2009 Author Share Posted October 9, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.