I am trying to complete an SQL insert query using php. The error I am returned with is: SCREAM: Error suppression ignored for Parse error: syntax error, unexpected T_STRING in C:\wamp\www\sign\db.php on line 28
I am using wamp and I have tested the query directly in php myadmin and it works fine. I don't know what the problem is.
Thanks in advance.
<?php
//variables for db
$username = "root";
$password = "";
$hostname = "127.0.0.1";
$dbname = "site";
//connection to the database
$con = mysql_connect($hostname, $username, $password);
if($con == FALSE)
{
echo 'Cannot connect to database' . mysql_error();
}
mysql_select_db($dbname, $con);
mysql_query("INSERT INTO users (full_name, first_name, dob, star_sign) VALUES ("test","test", "test", "test");";
?>
use single quotes instead.
mysql_query("INSERT INTO users (full_name, first_name, dob, star_sign) VALUES ('test','test', 'test', 'test');";
You need to backslash the quotes, here, else you close the statement
mysql_query("INSERT INTO users (full_name, first_name, dob, star_sign) VALUES (\"test\",\"test\", \"test\", \"test\");";
Alternatively you can replace them for single quotes
You need to fix your quotes:
// use single quotes
mysql_query("INSERT INTO users (full_name, first_name, dob, star_sign)
VALUES ('test','test', 'test', 'test');";
// Or...
// escape your double quotes
mysql_query("INSERT INTO users (full_name, first_name, dob, star_sign)
VALUES (\"test\",\"test\", \"test\", \"test\");";
What is happening (especially if you pay attention to syntax highlighting of the code in your question), is that simply using double quotes will end the string.
To fix this, you can use single quotes, or escape the double quotes.