大家好,所以我试图允许用户在提交数据后对其进行编辑。我有一个人员表,设置了一个自动递增的主键。这是我的代码中的一点让我烦恼//getting id from url
$StaffID = $_GET['StaffID'];
我不能为我的生活弄清楚它有什么问题,因为语法似乎是正确的。它告诉我索引是未识别的。
<?php
// including the database connection file
include_once("connect.php");
if(isset($_POST['update']))
{
$StaffID = $_POST['StaffID'];
// checking empty fields
if(empty($Name) || empty($Address) || empty($Telephone) || empty($BusinessID)) {
if(empty($Name)) {
echo "<font color='red'>Name field is empty.</font><br/>";
}
if(empty($Address)) {
echo "<font color='red'>Age field is empty.</font><br/>";
}
if(empty($Telephone)) {
echo "<font color='red'>Email field is empty.</font><br/>";
}
if(empty($BusinessID)){
echo "<font color='red'>Email field is empty.</font><br>/";
}
} else {
//updating the table
$result = mysqli_query($conn, "UPDATE staff SET Name='$Name',Address='$Address',Telephone='$Telephone', BusinessID='$BusinessID' WHERE StaffID = $StaffID");
//redirectig to the display page. In our case, it is index.php
header("Location: HomePHP.php");
}
}
?>
<?php
//getting id from url
$StaffID = $_GET['StaffID']; // <---- ERROR
//selecting data associated with this particular id
$result = mysqli_query($conn, "SELECT * FROM staff WHERE StaffID=$StaffID");
while($res = mysqli_fetch_array($result))
{
$Name = $res['Name'];
$Address = $res['Address'];
$Telephone = $res['Telephone'];
$BusinessID = $res['BusinessID'];
}
?>
答案 0 :(得分:0)
您应首先更改语法以防止SQL注入。我想你的问题将会得到解决。
0