运行时出现MySQL错误:
1972-11-08AlfredLibrejaCorallesLakeShore140 Rosal Street Loma Biñan Laguna
Notice: Undefined index: myfile in C:\xampp\htdocs\taugamma\update_member.php on line 13
Notice: Undefined index: idd in C:\xampp\htdocs\taugamma\update_member.php on line 14
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 ''' at line 12
这是我的代码: update_member.php
$bd1 = $_POST['bd1'];
$bd2 = $_POST['bd2'];
$bd3 = $_POST['bd3'];
echo $bd = mysqli_real_escape_string($con, ($bd1 . '-' . $bd2 . '-' . $bd3));
echo $fname = mysqli_real_escape_string($con, $_POST['fname']);
echo $lname = mysqli_real_escape_string($con, $_POST['lname']);
echo $mname = mysqli_real_escape_string($con, $_POST['shadow']);
echo $mchapter = mysqli_real_escape_string($con, $_POST['pob']);
echo $address = mysqli_real_escape_string($con, $_POST['address']);
echo $photo = mysqli_real_escape_string($con, $_FILES['myfile']['name']);
echo $id = mysqli_real_escape_string($con, $_POST['idd']);
$query = "UPDATE
tblmembers
SET
firstName = '" . $fname . "',
lastName = '" . $lname . "',
middleName = '" . $mname . "',
birthday = '" . $bd . "',
motherChapter = '" . $mchapter . "',
address = '" . $address . "',
photo = '" . $photo . "'
WHERE
ID = " . $id . "'";
if(!mysqli_query($con,$query)){
echo 'Error' . mysqli_error($con);
}else{
header("Location: show_all.php");
}
mysqli_close($con);
?>
这是我的HTML或表单代码, update.html
<form action="update_member.php" method="post">
<table border="0" width="100%" height="1400px">
<tr>
<td colspan="4" width="15%" style="background-color: #191919;"></td>
<td colspan="4" height="5%" style="font-size: 20px; font-weight: bold; background-color: #191919; color: #FFF056;">
<span>Update Member Data</span>
</td>
</tr>
<tr>
<td colspan="4">
</td>
<td style="background-color: 191919;"></td>
<td height="3%" class="labels">ID: </td>
<td> <input type="text" value="<?php echo $_POST['ided'] ?>" name="idd" disabled></td>
</tr>
<tr>
<td colspan="4">
</td>
<td style="background-color: 191919;"></td>
<td height="3%" class="labels">Firstname: </td>
<td> <input type="text" value="<?php echo $_POST['fName'] ?>" onkeydown="return alphaOnly(event)" name="fname"></td>
</tr>
<tr>
<td colspan="4">
</td>
<td style="background-color: 191919;"></td>
<td height="3%" class="labels">Lastname: </td>
<td> <input type="text" value="<?php echo $_POST['lName'] ?>" onkeydown="return alphaOnly(event)" name="lname"></td>
</tr>
<tr>
<td colspan="4">
</td>
<td style="background-color: 191919;"></td>
<td height="3%" class="labels">Middlename: </td>
<td>
<input type="text" onkeydown="return alphaOnly(event)" value="<?php echo $_POST['mName'] ?>" id="shadow" name="shadow">
</td>
</tr>
<tr>
<td colspan="4">
</td>
<td style="background-color: 191919;"></td>
<td height="3%" class="labels">Birthday: </td>
<td>
<input type="text" maxlength="4" size="3" name="bd1" id="bd1" value="<?php echo $_POST['bd1'] ?>" onkeypress="return isNumberKey(event)"> / <input type="text" value="<?php echo $_POST['bd2'] ?>" size="1" name="bd2" maxlength="2" onkeypress="return isNumberKey(event)"> / <input type="text" value="<?php echo $_POST['bd3'] ?>" maxlength="2" size="1" name="bd3" onkeypress="return isNumberKey(event)"> yyyy / mm / dd
</td>
</tr>
<tr>
<td colspan="4">
</td>
<td width="10%" style="background-color: 191919;"></td>
<td height="3%" class="labels">Mother Chapter: </td>
<td> <input type="text" name="pob" value="<?php echo $_POST['mChapter'] ?>" onkeydown="return alphaOnly(event)"></td>
</tr>
<tr>
<td colspan="4">
</td>
<td style="background-color: 191919;" width="10%"></td>
<td height="3%" class="labels">Address: </td>
<td> <input type="text" value="<?php echo $_POST['address'] ?>" name="address"></td>
</tr>
<tr>
<td colspan="4">
</td>
<td style="background-color: 191919;" width="10%"></td>
<td height="3%" class="labels">I.D. No.: </td>
<td> <input type="text" value="<?php echo $_POST['idNum'] ?>" name="idnum"></td>
</tr>
<tr>
<td colspan="4">
</td>
<td style="background-color: 191919;" width="10%"></td>
<td height="3%" class="labels">Photo: </td>
<td> <input type="file" id="myfile" name="myfile"></td>
</tr>
<tr>
<td colspan="4" style="background-color: 191919;"></td>
<td width="10%" height="3%" style="background-color: 191919;"></td>
<td style="background-color: 191919;">
</td>
<td width="60%" style="background-color: 191919;">
<input type="submit" onclick="showFileName()">
</td>
</tr>
<tr>
<td colspan="7"></td>
</tr>
</table>
</form>
它直接转到show_all.php并没有给出任何错误,但它没有任何改变。 :(
答案 0 :(得分:2)
您没有关闭$id
附近的报价:
WHERE
ID = " . $id . "'";
换句话说,它应该是:
WHERE
ID = '" . $id . "'";
答案 1 :(得分:0)
在更改标题位置之前,您的标题重定向将无法正常输出(使用echo)。
所以你要么:
if(!mysqli_query($con,$query)){
echo 'Error' . mysqli_error($con); // print your error to the screen
} else{
header("Location: show_all.php"); // do nothing as you've already echo'd further up the script
}
答案 2 :(得分:0)
主要错误来自此
$_POST['idd']
和
$_FILES['myfile']
修复idd来自哪里,即使你修复了查询,你也会从该变量$ id和$ photo中得到错误。
,您的查询应该是那样的
WHERE
ID = '" . $id . "' ";
^---you missed single quote here
答案 3 :(得分:0)
要解决第一个通知: 确保您在名为“myfile”的表单字段下发布文件。
echo $photo = mysqli_real_escape_string($con, $_FILES['myfile']['name']);
如果文件(照片)是可选的,您可以这样做:
echo $ photo = mysqli_real_escape_string($ con,(isset($ _ FILES ['myfile'])?$ _FILES ['myfile'] ['name']:“”);
修复第二通知: 确保post变量的真实名称是“idd”
echo $id = mysqli_real_escape_string($con, $_POST['idd']);
然后,删除“在这一行
” ID = " . $id . "'";