我正在爲一個學校項目創建一個在線移動重裝站點。但似乎我的更新聲明不起作用......但我認爲它的寫法是正確的,所以我無法弄清楚我的代碼中有什麼問題。更新聲明不適用於我的php代碼
我的代碼是..當用戶嘗試重新加載他的帳戶時,balance_table中的餘額列必須更新。
這裏是我的代碼: reloadaccount.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> </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> <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: ";
echo"<label for='month'>Month: </label> ";
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> ";
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> </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();
}
?>
試通'mysql_error'到'die'功能,讓你的代碼變得'的mysql_query($查詢)或死亡(mysql_error());' – Habibillah