Reputation: 857
this gives me an 'invalid syntax' error. what's so invalid about it?
$companyName = 'big company';
$address1 = 'big bay #8';
$address2 = 'some big warehouse';
$city = 'big city';
$province = 'AB';
$postalCode = 'T1T0N0';
$phone = '0123456789';
$email2 = '[email protected]';
$query = "INSERT INTO clients ";
$query .= "(companyName, address1, address2, city, province, postalCode, phone, email) ";
$query .= "VALUES (". $companyName.",".$address1.",".$address2.",".$city.",".$postalCode.",".$phone.",".$email2.")";
print ($query . "<br><br>");
$result = mysql_query($query, $connexion);
if ($result)
{
// Success!
echo "Fabulous! check the DB, we did it! :D<br>";
} else {
// Fail!
echo"CRAAAAAPP! something went wrong. FIX IT! :P<br>";
echo mysql_error();
}
i've triple checked the table and it's basically all VARCHAR(50), the names are correct and the sequence is correct (not that bad sequence would break it...).
What am I missing? ... and NO, connexion is NOT misspelled...
Upvotes: 0
Views: 111
Reputation: 37364
You have a bunch of string variables that should be enclosed in single quotes (and properly escaped).
query = "INSERT INTO clients ";
$query .= "(companyName, address1, address2, city, province, postalCode, phone, email) ";
$companyName = mysql_real_escape_string($company_name);
//... etc - escape all other variables
$query .= "VALUES ('". $companyName."',"'.$address1."','".$address2."','".$city."','".$postalCode."','".$phone."','".$email2."')";
Upvotes: 2
Reputation: 5579
You're inserting text and not surrounding the text with single quotes. Highly recommend that you change to using a parameterized query.
Upvotes: 1