我正在尝试添加一个更新功能,其工作方式如下:表单将有一个添加,搜索,更新按钮,其名称如下所述。在搜索按钮上,将从数据库中获取值,并将返回到我们可以编辑它然后更新的表单的文本框中。我无法做到这一点。 我正在尝试使用以下code.M直接得到结果错误消息不知道我哪里出错了
<html>
<head>
<?php
include 'dbconfig.php';
$fname="";
$lname="";
$age="";
$email="";
?>
</head>
<body>
<form action="sql.php" method="POST">
<input type="text" name="fname" placeholder="Fname" value="<?php echo $fname;?>"><br>
<input type="text" name="lname" placeholder="Lname" value="<?php echo $lname;?>"><br>
<input type="number" name="age" placeholder="Age"value="<?php echo $age;?>"><br>
<input type="email" name="email" placeholder="Email" value="<?php echo $email;?>"><br><br>
<div>
<input type="submit" value="Insert" name="submit">
<input type="submit" value="search" name="search">
<input type="submit" value="Update" name="update">
</div>
</form>
</body>
<?php
function getPosts()
{
$posts = array();
$posts[0] = $_POST['fname'];
$posts[1] = $_POST['lname'];
$posts[2] = $_POST['age'];
$posts[3] = $_POST['email'];
return $posts;
}
if(isset($_POST['search']))
{
$data = getposts();
$search_query = "SELECT * from 'info' WHERE fname = $data[0]";
if($result = mysqli_query($conn,$search_query))
{
if(mysqli_num_rows($result))
{
while($row = mysqli_fetch_array($result))
{
$fname = $row['fname'];
$lname = $row['lname'];
$age = $row['age'];
$email = $row['email'];
}
}else{
echo 'no data found';
}
}else{
echo 'result error';
}
}
?>
</html>