我已经制作了一个编辑表格......但是当我按下编辑按钮时......它可以工作......当完成编辑后如果按下更新按钮...它会进入主页但没有更新字段。
edit.page
<body>
<table align="center">
<tr>
<td align="center">Edit data</td>
</tr>
<tr>
<td>
<table border="2">
<th>SL</th>
<th>name</th>
<th>address</th>
<th>action</th>
<?php
include"dbc.php";//database conncetion
$order = "select * from tbl_record";
$result = mysqli_query($con,$order);
while ($row=mysqli_fetch_array($result)){
echo ("<tr><td>$row[employees_number]</td>");
echo ("<td>$row[name]</td>");
echo ("<td>$row[address]</td>");
echo ("<td><a href=\"edit_form.php?id=$row[employees_number]\">Edit</a></td></tr>");
}
mysqli_close($con);
?>
</table>
</td>
</tr>
</table>
</body>
</html>
编辑表格
<body>
<table border=2>
<tr>
<td align=center>Form Edit Employees Data</td>
</tr>
<tr>
<td>
<table border="1">
<?php
include "dbc.php";//database connection
$id = $_GET["id"];
$order = "SELECT * FROM tbl_record where employees_number='$id'";
$result = mysqli_query($con,$order);
$row = mysqli_fetch_array($result);
?>
<form method="post" action="edit_data.php">
<input type="hidden" name="id" value="<?php echo "$row[employees_number]"?>">
<tr>
<td>Name</td>
<td>
<input type="text" name="name"
size="20" value="<?php echo "$row[name]"?>">
</td>
</tr>
<tr>
<td>Address</td>
<td>
<input type="text" name="address" size="40"
value="<?php echo "$row[address]"?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>
</body>
更新页面
<?php
//edit_data.php
include "dbc.php";
if (isset($_POST['submit']))
{
$id = $_GET['id'];
$name = $_POST["name"];
$address = $_POST["address"];
mysqli_query("UPDATE tbl_record SET name='$name', address='$address' WHERE employees_number='$id'")
or die(mysqli_error());
}
header("location:edit.php");
?>
答案 0 :(得分:0)
根据您的评论“我现在收到此错误mysqli_query()预计至少有2个参数,1个给定...用于更新页面”
将您的连接参数添加到查询中:
mysqli_query("UPDATE
它的内容为
mysqli_query($con, "UPDATE ...
另外,您的提交按钮应显示为:
<input type="submit" name="submit" value="Edit">
现在它中的name="submit value"
与它的条件语句不匹配
if (isset($_POST['submit']))