Kishan Kumar

Kishan Kumar

  • 1.7k
  • 127
  • 5k

update data in php with condition

Mar 28 2018 1:46 AM
I make a registration page.
So Registration page ready and fetch data with page view data.
so update option not working some errors....
attach all file zip folder with database...
 
Error showing this 
 
Notice: Undefined variable: conn in C:\xampp\htdocs\registration\update.php on line 25

Fatal error: Call to a member function query() on null in C:\xampp\htdocs\registration\update.php on line 25 
 
 
Please resolve.......or new code comment....
Thanks so much.... 
 
 
 
<?php
if(!isset($_GET['id']))
{
exit('User Not Exists.');
}
$mysqli = new mysqli("localhost", "root", "", "test");
// Check connection
if($mysqli === false){
die("ERROR: Could not connect. " . $mysqli->connect_error);
}
// Attempt select query execution
$sql = "SELECT * FROM record where id = ".$_GET['id'];
if($result = $mysqli->query($sql)){
if($result->num_rows > 0){
$row = $result->fetch_array();
}
}
if(isset($_POST['update']))
{
$sql = "UPDATE record SET name='".$_POST['name']."', email='".$_POST['email']."', mobile='".$_POST['mobileno']."', address='".$_POST['address']."' WHERE id=".$_GET['id'];
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
}
?>
<html>
<title></title>
<head>
</head>
<body>
<div id="page-wrapper">
<!----Add Student Start---->
<form action="" method="post">
<div class="container">
<h1>Registration</h1>
<table>
<p> Name:-<span style="color:red;">*</span><input type="text" name="name" value="<?=$row['name'];?>" placeholder=" name" id=""/></p>
<p>Email<span style="color:red;">*</span><input type="text" name="email" value="<?=$row['email'];?>" id=""/></p></br>
<p>Address<span style="color:red;">*</span><input type="text" name="address" id="" value="<?=$row['address'];?>" /></p></br>
<p>Mobile No<span style="color:red;">*</span><input type="text" name="mobileno" id="" value="<?=$row['mobileno'];?>" /></p></br>
<input type="submit" name="update" value="update" id=""/></p></br>
</table>
</div>
</form>
</div>
</body>
</html>

Attachment: Register.zip

Answers (1)