MySQL杀死进程是用户没有得到足够的点PHP [英] MySQL kill process is user don't got enough points PHP

查看:124
本文介绍了MySQL杀死进程是用户没有得到足够的点PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码如同用户点击提交,他得到一张票(lodd)和失去五分,因为他买了一张票五分。但我错过了一个用户没有得到五点,他不能买。我想如果用户没有得到足够的积分,然后回声说(例子):

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.

我该怎么办?

<?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 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);


推荐答案

首先,不推荐使用mysql_ *改变它们在某一点。一个选项是使用: MySQLi

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";
}

这篇关于MySQL杀死进程是用户没有得到足够的点PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆