eshi eshi - 3 months ago 8
MySQL Question

Database does not update, mysql_error does not show errors

I've seen the related solutions about this and tried it but none of those works.
This is my code for Updating Database, the mysql_error shows no sign of error. Don't know what to do. Help!

<?php
mysql_select_db("dbUsers");
if(isset($_POST['btnSave'])){

$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$address=$_POST['address'];

$query1 =("UPDATE `webuser` SET `firstname`='".$firstname."',
`lastname`='".$lastname."',`address`='".$address."'
WHERE empNo = '".$selEmp."' ");

$result = mysql_query($query1) or die(mysql_error());
}
mysql_close($conn);

?>

Answer

Change the update query like this. Since the braces are not allowed.

Ensure that your empNo is present at the time while updating.

<?php
mysql_select_db("dbUsers");     
if(isset($_POST['btnSave'])){
$selEmp = $_POST['emp_id'];
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$address=$_POST['address'];
$query1 ="UPDATE `webuser` SET `firstname`='".$firstname."',
`lastname`='".$lastname."',`address`='".$address."'
WHERE empNo = '".$selEmp."'";    
$result = mysql_query($query1) or die(mysql_error());
}
mysql_close($conn);
?>

<form method="POST" action="">
    <input type="hidden" name="emp_id" value="<?php echo $data['id']; ?>" />
    <input type="text" name="firstname" value="<?php echo $data['firstname']; ?>" />
    <input type="text" name="lastname" value="<?php echo $data['lastname']; ?>" />
    <textarea name="address"><?php echo $data['address']; ?></textarea>
    <input type="submit" name="btnSave" value="UPDATE" />
</form>
Comments