php and mysql - insert works but update does not work

advertisements

what is wrong with my code, as insertion works fine, but update not working. I have copied the updaet's query from phpmyadmin and changed static values to variable

<?php
if (isset($_POST['submitContactInfo'])) {
    $socityId = $_SESSION['socityid'];
    $city = $_POST['city'];
    $pin = $_POST['pin'];
    $state = $_POST['state'];
    $telephone = $_POST['telephone'];
    $mobile = $_POST['mobile'];
    $email = $_POST['email'];
    $address = $_POST['address'];

    $sql = "INSERT INTO `_abc1`.`profile` (SOCIETY_ID,ADDR,CITY,PIN,STATE,TEL,MOBILE,EMAIL) VALUES ('$socityId','$address','$city','$pin','$state','$telephone','$mobile','$email');";

    $sql = "UPDATE `_abc1`.`profile` SET `ADDR` = '$address', `CITY` = '$city', `PIN` = '$pin', `STATE` = '$state', `TEL` = '$telephone', `MOBILE` = '$mobile', `EMAIL` = '$email' WHERE `society_profile`.`SOCITY_ID` = '$socityId'; ";

    $res = mysql_query($sql);
}
?>


You have a typo in your update. You have SOCITY_ID when in the first query it is SOCIETY_ID

try

$sql = "UPDATE `_abc1`.`profile` SET `ADDR` = '$address', `CITY` = '$city', `PIN` = '$pin', `STATE` = '$state', `TEL` = '$telephone', `MOBILE` = '$mobile', `EMAIL` = '$email' WHERE `SOCIETY_ID` = '$socityId'; ";

Also, as mentioned you should use mysqli_query instead of these old deprecated functions.

http://www.php.net/manual/en/mysqli.query.php