0

I'm trying to insert received values into postgresql table using php. I can't figure out why this statement doesn't work

  $query = "INSERT INTO user_info (name, emailAddress, phoneNumber, jobDesc) VALUES ('" . $name . "," . $emailAddr . "," . $phoneNumber . "," . $jobDesc ."')";

I get this error:

Query failed: ERROR:  column "emailaddress" of relation "user_info" does not exist

However, I tried this one:

$query = "INSERT INTO user_info VALUES ('" . $name . "," . $emailAddr . "," . $phoneNumber . "," . $jobDesc ."')";

It works, but it inserts all values into first column!

I'm not sure what I'm missing here!

1 Answer 1

1

I think you are missing a whole host of single quotes in your VALUES list...

$query = "INSERT INTO user_info (name, emailAddress, phoneNumber, jobDesc) VALUES ('" . $name . "','" . $emailAddr . "','" . $phoneNumber . "','" . $jobDesc ."')";
Sign up to request clarification or add additional context in comments.

8 Comments

Is emailAddress spelled correctly or even exists? It seems to be taking issue with that column.
Yes, and its type is character varying. would that be the issue by any chance?
I removed the email value then the same error appears with the next value "phoneNumber"
Which SQL are you sending. You said you tried one with the columns and one without the columns? Are you doing this one: $query = "INSERT INTO user_info (name, emailAddress, phoneNumber, jobDesc) VALUES ('" . $name . "','" . $emailAddr . "','" . $phoneNumber . "','" . $jobDesc ."')";?
Also, what is special about the name column? It seems to be working. Is it set up differently?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.