I am trying to add an update functionality which work as follows: A form will have an add,search,update button which works as the name describes. On search button the values will be fetched from database and will be retrive into the textbox of the form where we can edit it and then update. Am unable to achieve this. I am trying with following code.M directly getting result error message dont know where i am going wrong
<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>