如果在PHP mysql查询

时间:2014-04-11 04:29:19

标签: php mysql

我正在使用基于Sistem的服务器,因此用户可以将钱存入磁卡(我从磁卡获取ID并通过PHP和MySQL进行操作)

这个系统工作正常,我只是错过了比较,所以我不会从用户那里减去更多的钱而不是他实际上我认为PHP如果我得到了价值,但它不起作用我不知道为什么, 有谁能够帮我?

继承我的代码

    <?php
$numero  = $_POST["numero"];
$monto   = abs($_POST["monto"]);
$monto   = -$monto;
$con     = mysqli_connect("localhost", "usrname", "PASSWD", "TABLE");
$usuario = $_POST["username"];

if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysql_query($con, "SELECT Clientes.Nombre, sum(Mov_ctes.Movimiento) FROM
    Clientes NATURAL LEFT JOIN Mov_ctes WHERE cliente_id=$numero");
$row    = mysqli_fetch_array($result);

if ($row[0] > $monto) {
    mysqli_query($con, "INSERT INTO Mov_ctes(Cliente_id,Movimiento,Fecha)
    VALUES($numero,$monto,NOW())");
    mysqli_close($con);

    echo "<h1>carged  $" . abs($monto) . "  to client </h1>";
}

?>

   <a href='u.php?username=<?php echo $usuario; ?>' style='text-decoration:none;'><input
    type='button' value='Menu principal' style='width:120px; height:30px'></a>

提前tx!

1 个答案:

答案 0 :(得分:0)

改变这个 -

$result = mysqli_query($con, "SELECT Clientes.Nombre, sum(Mov_ctes.Movimiento) as sum_amount FROM
Clientes NATURAL LEFT JOIN Mov_ctes WHERE cliente_id=$numero");
$row    = mysqli_fetch_array($result);

if ($row['sum_amount'] > $monto) 
{

同样由@Hanky发现 - 将mysql_query更改为mysqli_query