php 杀死mysql进程,MySQL杀死进程是用户没有得到足够的点PHP

The coding below works like when a user clicks submit, he get one ticket (lodd) and loses five points because he bought one ticket for five points. But I miss when a user don't get five points he can't buy. I want that if the user doesn't get enough points then an echo says (example):

Sorry, but you need at least five points to buy a ticket.

How can I do that? Now people only go in minus if they buy more than they have.

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 the 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`-5) WHERE `username` = '".$username."'";

mysql_query($insert);

// Other code

$insert = "UPDATE `users` SET `lodd` = (`lodd` +1) WHERE `username` = '".$username."'";

mysql_query($insert);

mysql_query($insert);

header('location: succes.php');

?>

This is the code that give people one ticket for five points:

$insert = "UPDATE `users` SET `points` = (`points`-5) WHERE `username` = '".$username."'";

mysql_query($insert);

// Other code

$insert = "UPDATE `users` SET `lodd` = (`lodd` +1) WHERE `username` = '".$username."'";

mysql_query($insert);

mysql_query($insert);

解决方案

First, mysql_* are deprecated so you should look at changing them at some point. One option is to use: MySQLi

Back to your question, you could do this:

$insert = "UPDATE `users` SET `points` = (`points`-5) WHERE `username` = '".$username."' and points > 5";

mysql_query($insert);

if (mysql_affected_rows() > 0)

{

// other codes

$insert = "UPDATE `users` SET `lodd` = (`lodd` +1) WHERE `username` = '".$username."'";

mysql_query($insert);

}else{

echo "You don't have enough points";

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值