0

I am creating a simple mysql database but I get the following error: Parse error: syntax error, unexpected 'aasda' (T_STRING) on line: VALUES ("aasda", "sa", "asda", 43, "ada")");

Here is the code:

$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);

I don't understant what I am doing wrong. Thank you for youre help and patience!

Point89
  • 455
  • 1
  • 4
  • 9

2 Answers2

1

use single quote

mysql_query("INSERT INTO Users (username, firstname, lastname, age, emailadress)
             VALUES ('aasda', 'sa', 'asda', 43, 'ada')");

and one more thing, your query is vulnerable against SQL Injection, please take timet read article below to protect yourself against SQLInjection

Community
  • 1
  • 1
John Woo
  • 258,903
  • 69
  • 498
  • 492
  • you're welcome! also, please take time to read this article [**Best way to prevent SQL injection in PHP**](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) – John Woo Oct 28 '12 at 10:42
1
mysql_query("INSERT INTO Users (username, firstname, lastname, age, emailadress)
VALUES ('aasda', 'sa', 'asda', 43, 'ada')");
Reflective
  • 3,854
  • 1
  • 13
  • 25