Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Update语句对我的php代码无效_Php_Mysql_Sql_Sql Update - Fatal编程技术网

Update语句对我的php代码无效

Update语句对我的php代码无效,php,mysql,sql,sql-update,Php,Mysql,Sql,Sql Update,我正在为一个学校项目创建一个在线移动重新加载站点。但我的更新声明似乎不起作用。。。但我认为它写的是正确的,所以我无法找出代码中的错误 我的代码的作用。。当用户尝试重新加载其帐户时,必须更新余额表中的余额列 这是我的密码: reloadcount.php <?php if(!isset($_POST['send'])) { $usernumber = "09392316162"; mysql_connect("localhost", "root", ""); mysq

我正在为一个学校项目创建一个在线移动重新加载站点。但我的更新声明似乎不起作用。。。但我认为它写的是正确的,所以我无法找出代码中的错误

我的代码的作用。。当用户尝试重新加载其帐户时,必须更新余额表中的余额列

这是我的密码: reloadcount.php

<?php
if(!isset($_POST['send']))
{
    $usernumber = "09392316162";
    mysql_connect("localhost", "root", "");
    mysql_select_db("eloadretailer_db");
    $query0 = "SELECT * FROM `balance_table` WHERE `user_number` = $usernumber";
    $result = mysql_query($query0);
    echo"<form method='post' action='".$_SERVER['PHP_SELF']."'>";
    while($row = mysql_fetch_array($result))
    {
        $balance = $row['balance'];
    }
    echo"<input type='hidden' name='balance' value='".$row['balance']."' />";
    echo"<p>&nbsp;</p>";
    echo"<p>";
    echo"<label for='creditcardtype'>Credit Card Type: </label>";
    echo"<select name='creditcardtype' id='creditcardtype'>";
    echo"<option selected='selected'>Choose Credit Card</option>";
    echo"<option>Master Card</option>";
    echo"<option>Visa</option>";
    echo"</select>&nbsp;&nbsp;<img src='pics/creditcard.jpg' >";
    echo"</p>";
    echo"<p>";
    echo"<label for='creditcardnumber'>Credit Card Number: </label>";
    echo"<input type='text' name='creditcardnumber' id='creditcardnumber' />";
    echo"</p>";
    echo"<p>Expiration Date: &nbsp;&nbsp;";
    echo"<label for='month'>Month: </label>&nbsp;";
    echo"<select name='month' id='month'>";
    echo"<option selected='selected'>Month</option>";
    echo"<option>January</option>";
    echo"<option>February</option>";
    echo"<option>March</option>";
    echo"<option>April</option>";
    echo"<option>May</option>";
    echo"</select>";
    echo"<label for='year'>Year: </label>&nbsp;";
    echo"<select name='year' id='year'>";
    echo"<option selected='selected'>Year</option>";
    echo"<option>2020</option>";
    echo"<option>2019</option>";
    echo"<option>2018</option>";
    echo"<option>2017</option>";
    echo"<option>2016</option>";
    echo"<option>2015</option>";
    echo"<option>2014</option>";
    echo"<option>2013</option>";
    echo"</select>";
    echo"</p>";
    echo"<p>";
    echo"<label for='billingaddress'>Billing Address: </label>";
    echo"<textarea name='billingaddress' cols='40' id='billingaddress'>Billing Name, Street Address, City</textarea>";
    echo"</p>";
    echo"<p>";
    echo"<label for='zipcode'>Zip Code: </label>";
    echo"<input type='text' name='zipcode' id='zipcode' />";
    echo"</p>";
    echo"<p>";
    echo"<label>Amount to Load:";
    echo"<select name='amount' id='amount'>";
    echo"<option>Amount</option>";
    echo"<option value='100'>100</option>";
    echo"<option value='500'>500</option>";
    echo"<option value='1000'>1000</option>";
    echo"<option value='2000'>2000</option>";
    echo"<option value='3000'>3000</option>";
    echo"<option value='5000'>5000</option>";
    echo"</select>";
    echo"</label>";
    echo"</p>";
    echo"<p>&nbsp;</p>";
    echo"<p>";
    echo"<input type='submit' name='send' id='sendtransaction' value='Send Transaction' />";
    echo"</p>";
    echo"</form>";
}
else
{
    $connection = mysql_pconnect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("eloadretailer_db") or die(mysql_error());

    $usernumber = "09392316162"; // its data type is varchar because if its int, 0 cannot be place before number 9

    $balance = mysql_real_escape_string($_POST['balance']);

    $amount = mysql_real_escape_string( $_POST['amount']);
    $totalbalance =  $balance+$amount;
    echo"balance = $totalbalance"; // $totalbalance is working...

    //the data type of balance is int 
        //and user_number is varchar                        
    $query = "UPDATE `balance_table` SET `balance`= $totalbalance WHERE `user_number` = $usernumber"; // this code is not working.. i dont know why...

    mysql_query($query)or mysql_error();
}
?>

首先打印查询并在查询分析器上运行如果查询在分析器上运行,则您的查询是正确的,我认为在where条件下

     $query = "UPDATE `balance_table` 
           SET 
             `balance`= $totalbalance 
           WHERE 
             `user_number` = '".$_SESSION['cart']['session_id']."'";

由于
user\u number
varchar
您应该将其括在引号中

您的查询应该是

$query = "UPDATE `balance_table` SET `balance`= $totalbalance 
          WHERE `user_number` = '".$usernumber."'";

尝试将
mysql\u error
传递到
die
函数,使您的代码成为
mysql\u查询($query)或die(mysql\u error())