我认为PHP错误无法弄清楚与SQL的关系

时间:2010-04-02 19:45:54

标签: php sql postgresql

好的,错误出现在这里的代码

    if($error==false) {

        $query = pg_query("INSERT INTO chatterlogins(firstName, lastName, gender, password, ageMonth, ageDay, ageYear, email, createDate) VALUES('$firstNameSignup', '$lastNameSignup', '$genderSignup', md5('$passwordSignup'), $monthSignup, $daySignup, $yearSignup, '$emailSignup', now());");
        $query = pg_query("INSERT INTO chatterprofileinfo(email, lastLogin) VALUES('$email', now())";);
        $_SESSION['$userNameSet'] = $email;
        header('Location: signup_step2.php'.$rdruri);

    }
谁知道我做错了什么???对不起是如此不明确,但我已经盯着它看了10分钟,我无法弄明白。

3 个答案:

答案 0 :(得分:2)

$query = pg_query("INSERT INTO chatterprofileinfo(email, lastLogin) VALUES('$email', now())";);

靠近末尾的分号(;)放错了位置。它应该在字符串中:

$query = pg_query("INSERT INTO chatterprofileinfo(email, lastLogin) VALUES('$email', now());");

答案 1 :(得分:0)

在您的示例中,未引用monthSignup,daySignup和yearSignup。

答案 2 :(得分:0)

当查询失败时,pg_query()返回false。 pg_last_error()返回上一次操作的错误消息 希望所有这些变量 - $ firstNameSignup,$ lastNameSignup,$ genderSignup ...除了$ passwordSignup-已经通过pg_escape_string()正确转义

if($error==false) {
  $query = "
    INSERT INTO
      chatterlogins
      (
        firstName, lastName, gender, password,
        ageMonth, ageDay, ageYear, email, createDate
      )
      VALUES
      (
        '$firstNameSignup', '$lastNameSignup', '$genderSignup', md5('$passwordSignup'),
        $monthSignup, $daySignup, $yearSignup, '$emailSignup', now()
      )
  ";
  echo '<pre>Debug: query=', htmlspecialchars($query) , '</pre>';
  $rc = pg_query($query);
  if ( !$rc ) {
    die('pg_query failed: ' . htmlspecialchars(pg_last_error()) );
  }


  $query = "
    INSERT INTO
      chatterprofileinfo
      (email, lastLogin)
    VALUES
      ('$email', now())
  ";
  echo '<pre>Debug: query=', htmlspecialchars($query) , '</pre>';
  $rc = pg_query($query);
  if ( !$rc ) {
    die('pg_query failed: ' . htmlspecialchars(pg_last_error()) );
  }

  $_SESSION['$userNameSet'] = $email;
  header('Location: signup_step2.php'.$rdruri);
}