PHP error can't figure it out something to do with SQL stuff I think

Ok the error is showing up somewhere in this here code

    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);

    }

anyone see what I did wrong??? sorry for being so unspecific but ive been staring at it for 10 mins and I can't figure it out.

Answers


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

The semicolon (;) near the end is misplaced. It should be inside the string:

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

in your example, monthSignup, daySignup, and yearSignup aren't quoted.


When the query fails pg_query() returns false. pg_last_error() returns the error message of the last operation. Hopefully all those variables -$firstNameSignup, $lastNameSignup, $genderSignup ... except $passwordSignup- have been properly escaped via 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);
}

Need Your Help

ASP.NET authentication for custom API

php authentication asp.net-web-api

I know this is a pretty discussed topic but i'm struggling in finding a solution for my case.

Bad alloc is thrown

c++ memory boost bad-alloc

I am getting a 'bad_alloc while trying to work with boost managed shared memory. I've copied the boost example from their quick guide for the impatient and incorporated my own changes. MY code is b...