Jump to content

[SOLVED] sql help


Renlok

Recommended Posts

ive run a game or atleast im setting one up and ive got something where a user will gain a random amount of points every 6 hours, i cant get this to work either they always get the random points whenever they want or they never can get them. ive no clue what the problem is. thanks in advance for any help the code is:

 

$limit1 = 21600;
//check user can play
$limit = time() - $limit1;
$run = mysql_query("SELECT * FROM gameplay WHERE userid='$userid' AND lastplay < '$limit' AND gameid='1'");
$check = mysql_num_rows($run);

// End Check
$points = $row['points'];
$userid = $row['id'];
echo "<p align=center>Random points</p>";
if($check == 0)
{
$random = rand(1,1500);
$newpoints = $points+$random;
//update user points
$sql = "UPDATE users SET points='$newpoints' WHERE id = '$userid'";
$run = mysql_query($sql) or die($sql.mysql_error());
//update last played
$run = mysql_query("SELECT * FROM gameplay WHERE userid='$userid' AND gameid='1'");
$check = mysql_num_rows($run);
$time = time();
//if entry for this user already exists
if($check == '1')
{
$sql = "UPDATE gameplay SET lastplay='$time' WHERE userid='$userid' AND gameid='1'";
} else {
$sql = "INSERT INTO gameplay (userid, lastplay, gameid) VALUES ('$userid', '$time', '1')";
}
$run = mysql_query($sql) or die($sql.mysql_error());
echo "<p align=center>You recive $random points from the random points collection dont forget to come back in 6 hours to play again</p>";
} else {
echo "<p align=center><b>You cannot play right now, as you last played within 6 hours ago</b></p><p align=center><a href=\"http://www.roeonline.co.uk/arcade.php\">back to games</a></p>";
}

Link to comment
https://forums.phpfreaks.com/topic/45083-solved-sql-help/
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.