paulman888888 Posted June 29, 2008 Share Posted June 29, 2008 How do i make the players column go up 1, on row $_GET['gameid']? I have this so far <?php //i have my connection $thegameid=$_GET['gameid']; mysql_query("UPDATE players WHERE id='$thegameid' SET players = players + 1"); ?> Thankyou Paul Link to comment https://forums.phpfreaks.com/topic/112433-solved-php-mysql-help-please/ Share on other sites More sharing options...
Barand Posted June 29, 2008 Share Posted June 29, 2008 mysql_query("UPDATE players SET players = players + 1 WHERE id='$thegameid'"); Link to comment https://forums.phpfreaks.com/topic/112433-solved-php-mysql-help-please/#findComment-577236 Share on other sites More sharing options...
br0ken Posted June 29, 2008 Share Posted June 29, 2008 Your query is almost right, just ordered wrong. Also, some validation of the input is required. Try this... $thegameid = number_format($_GET['gameid'], 0, "", ""); // Format input as a number mysql_query("UPDATE players SET players = players + 1 WHERE id= $thegameid"); Link to comment https://forums.phpfreaks.com/topic/112433-solved-php-mysql-help-please/#findComment-577238 Share on other sites More sharing options...
jelly Posted June 29, 2008 Share Posted June 29, 2008 <?php $thegameid = (int)$_GET['gameid']; // id MUST be an integer value ?> :-) Link to comment https://forums.phpfreaks.com/topic/112433-solved-php-mysql-help-please/#findComment-577242 Share on other sites More sharing options...
br0ken Posted June 29, 2008 Share Posted June 29, 2008 <?php $thegameid = (int)$_GET['gameid']; // id MUST be an integer value ?> :-) Sorry to digress but if the value passed wasn't an int, would this return 0? I've always wondered that about typecasting. Link to comment https://forums.phpfreaks.com/topic/112433-solved-php-mysql-help-please/#findComment-577246 Share on other sites More sharing options...
jelly Posted June 29, 2008 Share Posted June 29, 2008 <?php if ($thegameid = (int)$_GET['gameid']) { mysql_query("UPDATE players SET players = players + 1 WHERE id= $thegameid"); } else { echo ('error'); } ?> If the value isn't int that will return 0. If $_GET['game'] = '123abc' that will return $thegameid = 123. -- jelly. Link to comment https://forums.phpfreaks.com/topic/112433-solved-php-mysql-help-please/#findComment-577256 Share on other sites More sharing options...
br0ken Posted June 29, 2008 Share Posted June 29, 2008 So in a way it's better than using number_format because that will only return a value greather than zero if the whole value is a true integer where as typecasting will remove the slightest bit of a number. Thanks Jelly! Link to comment https://forums.phpfreaks.com/topic/112433-solved-php-mysql-help-please/#findComment-577265 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.