【发布时间】:2012-12-01 17:06:29
【问题描述】:
我有一个带有用户系统的积分系统,人们可以用 50 积分升级到 [PRO] 用户。当他们注册时,会自动将 [user] 写入我的权限字段。但现在我想在采取行动后检查他们是否得到 50 分,然后将 [user] 替换为 [PRO],然后减去 50 分。
<?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========
$insert = "UPDATE `users` SET `points` = (`points`-50) WHERE `username` = '".$username."' and points > 50";
mysql_query($insert);
if (mysql_affected_rows() > 1)
{
// other codes
$insert = "UPDATE `users` SET `rights` = (`rights` [PRO]) WHERE `username` = '".$username."'";
mysql_query($insert);
header('location: succesupgrade.php');
}else{
echo "You don't have enough points to buy [PRO]";
}
?>
再次:我希望在人们购买 [PRO] 之后,[user] 被 [PRO] 替换。然后他们失去了 50 分。如果他们没有得到 50 分。 echo 说了些什么。
【问题讨论】:
-
@MarcB - 相同的程序,不同的问题。