我正在创建一个简单的mysql数据库,但我收到以下错误:Parse error: syntax error, unexpected 'aasda' (T_STRING)
在线:VALUES ("aasda", "sa", "asda", 43, "ada")");
以下是代码:
$con=mysql_connect("localhost","root","");
if (!$con)
{
die ("Could not connect: " . mysql_error());
}
if (mysql_query("CREATE DATABASE my_db",$con))
{
echo "Database created";
}
else
{
die("not");
}
mysql_select_db("my_db", $con);
$sql = "CREATE TABLE Users
(
username varchar(20),
firstname varchar(15),
lastname varchar(15),
age int,
emailadress varchar(20)
)";
mysql_query($sql,$con);
mysql_query("INSERT INTO Users (username, firstname, lastname, age, emailadress)
VALUES ("aasda", "sa", "asda", 43, "ada")");
mysql_close($con);
我不明白我做错了什么。谢谢你的帮助和耐心!
答案 0 :(得分:1)
使用单引号
mysql_query("INSERT INTO Users (username, firstname, lastname, age, emailadress)
VALUES ('aasda', 'sa', 'asda', 43, 'ada')");
还有一件事,您的查询容易受到SQL Injection
的攻击,请在下面阅读文章以保护自己免受SQLInjection
答案 1 :(得分:1)
mysql_query("INSERT INTO Users (username, firstname, lastname, age, emailadress)
VALUES ('aasda', 'sa', 'asda', 43, 'ada')");