gpt4 book ai didi

php - 更新语句不适用于我的 php 代码

转载 作者:行者123 更新时间:2023-11-30 01:16:06 25 4
gpt4 key购买 nike

我正在为学校项目创建一个在线移动重新加载网站。但我的更新语句似乎不起作用...但我认为它写得正确,所以我无法弄清楚我的代码中有什么问题。

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

这是我的代码:重新加载帐户.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();
}
?>

最佳答案

由于 user_numbervarchar,您应该将其括在引号中。

您的查询应该是

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

关于php - 更新语句不适用于我的 php 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19042366/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com