0

我的代码有什么问题,因为插入工作正常,但更新不起作用。我已经从 phpmyadmin 复制了 updaet 的查询并将静态值更改为变量

<?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);
}
?>
4

3 回答 3

1

您的更新中有错字。你有 SOCITY_ID 在第一个查询中它是 SOCIETY_ID

尝试

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

此外,如前所述,您应该使用 mysqli_query 而不是这些旧的不推荐使用的函数。

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

于 2013-03-14T18:17:52.273 回答
0
  • 首先,您应该考虑使用 mysqli 或 PDO 而不是标准的 mysql 类。
  • 其次,您还没有加入一个表,那么您希望它如何匹配您尝试查询的两个表?
于 2013-03-14T18:16:01.663 回答
0

尝试这个..

$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."'; ";
于 2013-03-14T18:17:57.280 回答