PHP ver gevorderde |
|
Ik ben bezig met spelletjes met scores.
Nu wil ik deze scores opslaan in mijn db.
<?php
include ('config.php');
$maand = date("Y-m");
$sql = "SELECT * FROM onlinegames WHERE gameid='$_POST[gameid]' AND userid='$_POST[userid]' AND maand='$maand'";
$query = mysql_query($sql);
$aantal = mysql_num_rows($query);
if ($aantal == "0") {
$post = "INSERT INTO onlinegames (gameid, userid, score, maand)
VALUES ('".$_POST['gameid']."', '".$_POST['userid']."', '".$_POST['score']."', '$maand')";
mysql_query ($post) or die (mysql_error());
} else {
$sql = "SELECT score FROM onlinegames WHERE gameid='".$_POST['gameid']."' AND userid='".$_POST['userid']." AND maand='$maand'";
$query = mysql_query($sql);
while ($obj = mysql_fetch_object($query)) {
$oudescore = $obj->score; }
if ($oudescore < $_POST[score]) {
$query = "UPDATE onlinegames SET score=".$_POST['score']." WHERE id=".$_POST['userid']." AND gameid=".$_POST['gameid']." AND maand=$maand";
mysql_query($query) or die (mysql_error());
}
}
mail ("driesverhees@gmail.com","Bericht","$_POST[score] en $_POST[userid] en $_POST[gameid]");
?>
<?php include ('config.php'); $sql = "SELECT * FROM onlinegames WHERE gameid='$_POST[gameid]' AND userid='$_POST[userid]' AND maand='$maand'"; if ($aantal == "0") { $post = "INSERT INTO onlinegames (gameid, userid, score, maand) VALUES ('".$_POST['gameid']."', '".$_POST['userid']."', '".$_POST['score']."', '$maand')"; } else { $sql = "SELECT score FROM onlinegames WHERE gameid='".$_POST['gameid']."' AND userid='".$_POST['userid']." AND maand='$maand'"; $oudescore = $obj->score; } if ($oudescore < $_POST[score]) { $query = "UPDATE onlinegames SET score=".$_POST['score']." WHERE id=".$_POST['userid']." AND gameid=".$_POST['gameid']." AND maand=$maand"; } } mail ("driesverhees@gmail.com","Bericht","$_POST[score] en $_POST[userid] en $_POST[gameid]"); ?>
Het opslaan lukt niet,het mailen wel.
Waar ligt de fout?
|