'Update statement in my project not updating data in table
I am trying to update the record of Employee.MY query shows the message "Employee record updated Successfully" but it is not updating in table My code goes like this
{
$eid=intval($_GET['uin']);
$uin=$_POST['uin'];
$fname=$_POST['firstName'];
$lname=$_POST['lastName'];
$email=$_POST['email'];
$department=$_POST['department'];
$recoffr=$_POST['recoffr'];
$mobileno=$_POST['mobileno'];
$sql="
update tblemployees
set FirstName = :fname
, LastName = :lname
, email = :email
, department = :department
, recoffr = :recoffr
, Phonenumber = :mobileno
where uin = :eid
";
$query = $dbh->prepare($sql);
$query->bindParam(':uin',$uin,PDO::PARAM_STR);
$query->bindParam(':fname',$fname,PDO::PARAM_STR);
$query->bindParam(':lname',$lname,PDO::PARAM_STR);
$query->bindParam(':email',$email,PDO::PARAM_STR);
$query->bindParam(':department',$department,PDO::PARAM_STR);
$query->bindParam(':recoffr',$recoffr,PDO::PARAM_STR);
$query->bindParam(':mobileno',$mobileno,PDO::PARAM_STR);
$query->execute();
$msg="Employee record updated Successfully";
}
My table structure is Table structure
Solution 1:[1]
You have assigned Uin to wrong Id
$query->bindParam(':eid',$uin,PDO::PARAM_STR);
not
$query->bindParam(':uin',$uin,PDO::PARAM_STR);
Solution 2:[2]
you can try this:
if (isset($_GET['uin'])) {
$ID = $_GET['uin'];
} else {
$ID = "";
}
$tblemployees_data = array();
$sql_query = "SELECT firstName, lastName, email, department, recoffr, mobileno
FROM tblemployees
WHERE uin = ?";
if ($query_category->prepare($sql_query)) {
// Bind your variables to replace the ?s
$query_category->bind_param('s', $ID);
// Execute query
$query_category->execute();
// store result
$query_category->store_result();
$query_category->bind_result($previous_category_image);
$query_category->fetch();
$query_category->close();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mahesh |
| Solution 2 | Sagor das |
