我的更新脚本有问题,我的脚本有问题吗?每当我运行它时,它只是显示回声“ERROR”。这是我的更新脚本:
<?PHP
$con = mysqli_connect("localhost","root","","testuser");
$choosed2 = $_POST['choosed2'];
$creditnew = $_POST['creditnew'];
$debitnew = $_POST['debitnew'];
$newid = $choosed2 - 1;
$bal = "SELECT balance FROM `bal` WHERE id=$newid;";
$chek = mysqli_query($con,$bal);
$row = mysqli_fetch_assoc($chek);
$old_balance = $row['balance'];
if ($old_balance == NULL){
$old_balance = 0;
}
$balancenew = $old_balance - $creditnew + $debitnew;
$up = "UPDATE `bal` SET debit='$debitnew' credit='$creditnew' balance='$balancenew' WHERE id='$choosed2'";
if(mysqli_query($con,$up))
{
echo "<div class='form' style='text-align:center; float:center;'><div style='font-weight:bold; font-size:20px; margin:10px'>UPDATE SUCCESS</div><br/><a href='index.php' style='margin:5px;' class='tombol'><< BACK</a><a href='Input.php' style='margin:5px;' class='tombol'>INPUT AGAIN</a></div>";
}else{
echo "<div class='form'><h3>ERROR</h3><br/><a href='balance.php'>Input again</a>";
}
?>
info:choosed2
是行ID。
任何人都可以帮助我吗?感谢。
答案 0 :(得分:1)
您在SQL语句中错过了逗号(,
)。您的SQL查询将是
$up = "UPDATE `bal` SET debit='$debitnew', credit='$creditnew', balance='$balancenew' WHERE id='$choosed2'";