php页面未更新
下面是我运行MySQL时的错误:php页面未更新,php,mysql,Php,Mysql,下面是我运行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_memb
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
这是我的代码:
更新_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,不给出任何错误,但不做任何更改 您没有在$id左右结束报价: 换句话说,它应该是:
WHERE
ID = '" . $id . "'";
在更改标头位置之前,当您使用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
}
主要错误来自于此
$_POST['idd']
及
修复idd的来源,即使修复了查询,也会从变量$id和$photo中得到错误
您的查询应该是这样的
WHERE
ID = '" . $id . "' ";
^---you missed single quote here
要确定第一个通知:
确保在名为:myfile的表单字段下发布文件
echo $photo = mysqli_real_escape_string($con, $_FILES['myfile']['name']);
如果文件照片是可选的,则可以执行以下操作:
echo$photo=mysqli\u real\u escape\u字符串$con,isset$\u文件['myfile']$_文件['myfile']['name']:
要修复第二个通知:
确保post变量的真实名称为idd
echo $id = mysqli_real_escape_string($con, $_POST['idd']);
然后,删除该行上的
ID = " . $id . "'";
有错误吗?@AbhikChakraborty错误在问题的开头。哪一行是第13行?@Barmar,没有,注意和错误之间有很大的不同。显式命令或php设置可以忽略通知。现在我发现了错误,但当它运行时,它会进行任何更改。但它没有给出任何错误@ABHIKChakrabortyth这解释了MySQL错误,但不是PHP未定义的索引错误。我的猜测是,您在表单中看到的内容与服务器端的预期不匹配。它仍然没有更新:我认为输出都是为了调试,所以最好不要重定向-在一些评论中,他说它没有更新数据库。重定向与此无关。以下是输出:注意:第13行C:\xampp\htdocs\taugamma\update\u member.php中的未定义索引:myfile注意:第1行C:\xampp\htdocs\taugamma\update\u member.php中的未定义索引:idd
$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);
?>
ID = " . $id . "'";