我有一个积分系统,我希望人们在输入/表格后再获得 1 分。直到现在我使用这个代码:
<?php
session_start();
//=============Configuring Server and Database=======
$host = 'localhost';
$user = 'root';
$password = '';
//=============Data Base Information=================
$database = 'login';
$conn = mysql_connect($host,$user,$password) or die('Server Information is not Correct'); //Establish Connection with Server
mysql_select_db($database,$conn) or die('Database Information is not correct');
//===============End Server Configuration============
//=============Starting Registration Script==========
$username = mysql_real_escape_string($_POST['txtusername']);
//=============To Encrypt Password===================
//============New Variable of Password is Now with an Encrypted Value========
if(isset($_POST['btnRegister'])) //===When I will Set the Button to 1 or Press Button to register
{
$query = mysql_query("SELECT * FROM quiz WHERE username='$username'");
if(mysql_num_rows($query) > 5 ){
echo "Sorry but you can only take a quize once:S";
}else{
$insert = "UPDATE `users` SET `points` = '".$points."' +1 WHERE `username` = '".$username."'";
mysql_query($insert);
mysql_query ("insert into quiz(username)values('$username')");
header('location: succes.php');
}
}
?>
但是这段代码似乎没有更新/添加 1,但它用 1 替换了那里的数字。所以如果我有 5 并且我运行这段代码,它会替换为 1,那么它会说 1。我该如何修复它添加/更新?因此,如果一个人有 3 分并运行代码,他会在获得 repacec 后获得 4 分:
$insert = "UPDATE `users` SET `points` = '".$points."' +1 WHERE `username` = '".$username."'";