Question


Amit Katrodiya

how to update record in database using php ?

Date = 2015-03-23

Comments by experts


Rajesh Kakadiya
2015-03-23

// check this solution for you

<html>
<body>
<?php
$con
=mysql_connect("localhost","username","password"); // connection to localhost
if(!$con)
  {
  die(
'Could not connect :'.mysql_error()); // showing error if having problem with username or password
  
}
mysql_select_db("database_name",$con); // select database from localhost
 
$value1=$_POST['value1'];
$value2=$_POST['value1'];
$id=$_POST['id'];
$sql="UPDATE table_name SET fname='$value1',lname='$value2' where id='$id')";  // Updating record into table
 
if(!mysql_query($sql,$con)) 
  {
  die(
'Error in updating record :'.mysql_error());  // if problem with tablename or any field name
  
}
echo 
"1 record added"// record Update successfully
mysql_close($con// close connection to server
?>
</body>
</html>


Type your Comment below and click to send comment