我正在做一個存儲日誌的工作,我一直在與這個代碼在過去的兩個小時沒有成功的戰鬥。出於某種原因,無論我檢查並重新檢查INSERT INTO查詢的代碼的次數,它都不起作用。爲什麼我的SQL「INSERT INTO」查詢不起作用?
請記住,我幾乎逐字(很明顯地改變了表單名稱和字段)從基本上具有相同功能並且工作100%的另一個頁面複製了該代碼。下面的代碼:
這是包含在交易被提交表單的頁面:
<?php
$script = '<script>
$(document).ready(function(){
$(".datepicker").datepicker();
}); </script>' ;
$title = "View/Edit Storage - " ;
include('inc/header.php');
?>
<table>
<tr>
<form action="transadded.php" name='addnewtransaction' method="POST">
<td><input type="text" name="moveID" size="20" value="<?php echo $results[moveid]; ?>" readonly> </td>
<td><select id="inoutselect" name="inorout">
<option value="Select">Select</option>
<option value="Storage In">Storage In</option>
<option value="Storage Out">Storage Out</option>
</select> </td>
<td><input type="text" name="numberofunits" size="20"></td>
<td><input type="text" name="dateoftransaction" size="20" class="datepicker"></td>
<td><input type="text" name="rrdt" size="20"> </td>
<td><input type="submit" value="Add" id="logsubmit"></td>
</form>
</table>
<br /><br />
<?php };?>
這裏查詢本身,又名 「transadded.php」:
<?php
$title = "Project Added - ";
include('inc/header.php');
$query = "INSERT INTO newtransaction (moveid, inout, units, transdate, refno) VALUES('$_POST[moveID]','$_POST[inorout]','$_POST[numberofunits]','$_POST[dateoftransaction]','$_POST[rrdt]')";
if(!mysqli_query($con,$query))
{
die ('Error: ' . mysqli_error($con));
}
echo '<div class="transstatus">' . '1 record added' . '</div>';
mysqli_close($con);
?>
頭,顯然,它包含了連接數據庫的功能,正如我所說的,另一個查詢可以正常工作,所以我知道這不是問題。當點擊提交按鈕,我得到網頁上的錯誤如下:
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'inout, units, transdate, refno) VALUES ('1234567','Storage In','81','09/11/2013'' at line 1
這裏,「1234567」,「存儲在」等都是我進入表單中的值。
我希望你能幫助我。我很困難!
此外,我知道我現在不受注射的保護。我打算稍後再研究,但我試圖首先理清功能。
如果沒有準備好語句,mysqli有什麼意義? – Davit
表結構是什麼樣的? – Fluffeh