我正在尝试将数据写入MySQL表,但在单击“提交”时继续获取“HTTP错误500”页面。我不认为它与表单有任何关系,但这里是使用的代码:
<form method="post" enctype="multipart/form-data" action="rma.php">
<p>
Start Date:<br />
<input type="date" name="datecomp"><br /><br />
<select name="action">
<option value="record">Record New Entry</option>
<option value="search">Search for Existing</option>
</select><br />
<br />
Status:<br />
<select name="status">
<option value="Complete">Complete</option>
<option value="Follow Up">Follow Up</option>
</select><br />
Last Name/Last 4:</br>
<input type="text" name="nameLast4" placeholder="last name, last 4 digits of social"></br>
Device/s:</br>
<input type="text" name="device" placeholder="(multiple separated by commas)"></br>
Device Serial Number/s:</br>
<input type="tel" name="serial" placeholder="..."></br>
New Serial Number:</br>
<input type="text" name="newser" placeholder="..."><br /><br />
Flagged:</br>
<input type="radio" name="flag" value="yes"> Yes <input type="radio" name="flag" value="no"> No </br><br />
Warranty Expired:</br>
<input type="radio" name="warranty" value="yes"> Yes <input type="radio" name="warranty" value="no"> No </br><br />
Date Returned to Vendor:</br>
<input type="date" name="returnDate"><br /><br />
UPS Tracking:<br />
<input type="tel" name="ups" placeholder="..."></br><br />
RMA Form Upload:
<input type="file" name="fileToUpload" id="fileToUpload"><br /><br />
RMA Number:<br />
<input type="text" name="RMA_#" placeholder="..."><br />
<br />
Date Completed:<br />
<input type="date" name="datecomp"><br /><br />
E.T.A. (If Available):<br />
<input type="date" name="eta"><br /><br />
Initials<br />
<input type="text" name="init"><br />
<textarea name="notes" cols="30" rows="5" placeholder="Optional Notes..."></textarea>
</br>
<input type="submit" name="submit" value="Submit"> <input type="reset" value="Clear Form"> 
</p>
</form>
然后是PHP ....
<?php
$action = $_POST['action'];
$status = $_POST['status'];
$name = $_POST['nameLast4'];
$dev = $_POST['device'];
$serial = $_POST['serial'];
$rmanum = $_POST['RMA_#'];
$flag = $_POST['flag'];
$ups = $_POST['ups'];
$warr = $_POST['warranty'];
$returndate = $_POST['returnDate'];
$newser = $_POST['newser'];
$eta = $_POST['eta'];
$rmaform = $_POST['fileToUpload'];
$datestart = $_POST['startdate'];
$datecomp = $_POST['datecomp'];
$init = $_POST['init'];
$comments = $_POST['notes'];
$servername = "localhost";
$username = "kylezeio_admin";
$password = "********";
$dbname = "kylezeio_RMA";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($action === "record"){
$sql = "INSERT INTO `kylezeio_RMA`.`RMA Records` (`ID`, `Complete/Follow up`, `Name/Last4`, `Device`, `Serial Number`, `RMA Number`, `Flagged`, `UPS Tracking`, `Warranty Expired`, `Date Returned`, `New Serial Number`, `E.T.A. (if available)`, `Date Completed`, `Date Started`, `Initials`, `Comments`) VALUES (NULL, $status, $name, $dev, $serial, $rmanum, $flag, $ups, $warr, $returndate, $newser, $eta, $datecomp, $datestart, $init, $comments);";
}
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
您还可以查看页面@ http://kylejoeckel.com/RMA%20Form.html
提前致谢...
修改
我错过了一个分号,所以我相信这就是为什么我得到500错误,现在我得到了这个:
错误:INSERT INTO kylezeio_RMA
。RMA Records
(ID
,Complete/Follow up
,Name/Last4
,Device
,Serial Number
,{ {1}},RMA Number
,Flagged
,UPS Tracking
,Warranty Expired
,Date Returned
,New Serial Number
,E.T.A. (if available)
,{{1 },Date Completed
,Date Started
)VALUES(NULL,Complete,joeckel,9999,cmdr,589437609287,l654651,yes,1z8e983756987,no,2016-11-21,356928679,2016-11-17 ,2016-11-08,,hg,test);
您的SQL语法有错误;查看与您的MariaDB服务器版本对应的手册,以便在第1行“hg,test”附近使用正确的语法
但我不知道它会引用什么语法错误。
答案 0 :(得分:1)
为了给你一个确切的答案,我需要看到你的表创建语句。 不过,让我们试一试。你只是缺少字符串引号。
试一试。
$sql = "INSERT INTO `kylezeio_RMA`.`RMA Records` (`ID`, `Complete/Follow up`, `Name/Last4`, `Device`, `Serial Number`, `RMA Number`, `Flagged`, `UPS Tracking`, `Warranty Expired`, `Date Returned`, `New Serial Number`, `E.T.A. (if available)`, `Date Completed`, `Date Started`, `Initials`, `Comments`)
VALUES
(NULL, $status, $name, $dev, $serial, $rmanum, $flag, $ups, $warr, $returndate, $newser, $eta, $datecomp, $datestart, '$init', '$comments');";