kabeersvohra
kabeersvohra

Reputation: 1059

Error when inserting into sql database using php

I have a program with a MySQL insert query:

        $sql = "INSERT INTO people (person_id, name, username, password, email, salt)
                VALUES ($person_id, $name, $username, $password, $email, $salt)";
        if ($con->query($sql) === TRUE) {
            successful();
        } else {
            unsuccessful("Error: " . $sql . "<br>" . $con->error);
        }

When I run the code I get this error:

Error: INSERT INTO people (person_id, name, username, password, email, salt) VALUES (2, Tom Jack, tjack95, 8a01fc598a676a249c5844bd3baf4f4d83cecdf2, [email protected], eb694539989fda2e17f79e70fb306f8911c3dee5)
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Jack, tjack95, 8a01fc598a676a249c5844bd3baf4f4d83cecdf2, [email protected], eb69' at line 2

The sql insert looks completely fine to me. What is the problem?

Upvotes: 0

Views: 2493

Answers (1)

John Conde
John Conde

Reputation: 219794

You're missing quotes around your string values:

$sql = "INSERT INTO people (person_id, name, username, password, email, salt)
            VALUES ($person_id, '$name', '$username', '$password', '$email', '$salt')";

Upvotes: 4

Related Questions