[英]I am developing php page for update function
when page is loaded it display error that id
, name
and address
is undefined. 加载页面时,它会显示错误消息: id
, name
和address
未定义。 These variable are getting on condition of edit, but i dont understand how to place these values in text filed 'value' for edit as this is not working. 这些变量处于编辑状态,但是我不明白如何将这些值放在文本“值”中进行编辑,因为这不起作用。 The main code is like this.*** also the code of update is not updating values but it displays your record is updated 主要代码是这样的。***更新代码也不是更新值,而是显示您的记录已更新
<?php
include 'server.php';
if (isset($_GET['edit'])) {
$id = $_GET['edit'];
$update = true;
$record = mysqli_query($con, "SELECT * FROM info WHERE id=$id");
if (count($record) == 1) {
$n = mysqli_fetch_array($record);
$name = $n['name'];
$address = $n['address'];
}
}
?>
<!-- Form -->
<!DOCTYPE html>
<html>
<head>
<title>CReate, Update</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<form method="post" action="php_code.php" >
<input type="hidden" name="id" value="<?php echo $id; ?>">
<input type="text" name="name" value="<?php echo $name; ?>">
<input type="text" name="address" value="<?php echo $address; ?>">
<div class="input-group">
<?php if ($update == true): ?>
<button class="btn" type="submit" name="update" >Update</button>
<?php else: ?>
<button class="btn" type="submit" name="submit" >save</button>
<?php endif ?>
</div>
</form>
<!-- Display -->
<?php
$i = 1;
$q = mysqli_query($con, "select*from info");
while ($f = mysqli_fetch_array($q)) {
?>
<table>
<th> sr N0</th>
<th> Name</th>
<th> address</th>
<th> Action</th>
<tr>
<td> <?php echo $i; ?> </td>
<td> <?php echo $f['name']; ?> </td>
<td> <?php echo $f['address']; ?> </td>
<td><a href="index.php?edit=<?php echo $f['id']; ?>" class="edit_btn" >Edit</a></td>
</tr>
<?php $i ++;
}
?>
</table>
</body>
</html>
<?php
include 'server.php';
if (isset($_POST['save']))
{
$name= $_POST['name'];
$add= $_POST['address'];
$q = "INSERT into info (name,address) VALUES ('$name', '$add')";
mysqli_query($con, $q);
echo "inserted";
}
if (isset($_POST['update']))
{
$uname= $_POST['name'];
$uaddress= $_POST['address'];
$q = "UPDATE info set name= '$uname', adress= '$uaddress' WHERE id = $id";
mysqli_query($con, $q);
echo "updated";
}
?>
Make 使
if (count($record) == 1 ) {
to 至
if (mysqli_num_rows($record) == 1 ) {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.