Hi I'm just trying to input two string variables into 2 fields of a database that are VarChars.

$name = "jear";
$pass = "jartt2";

$query = 'INSERT INTO `user` (`id`, `name`, `password`, `char_name`) VALUES (NULL, '$name', '$pass', 'test')';
$result = mysql_query($query);

This is the snippet of code that I'm trying to do. The database is connecting successfully and grabbing the table successfully. The error I get says:


Parse error: syntax error, unexpected T_STRING in /hermes/web10/b2810/moo.*****/*****/****** on line 14

I asterisked out the parts to my server. The file it is describing is the one that all the code is in, there are no includes or external docs being used.

Any help would be great! Thanks :)

Recommended Answers

All 2 Replies

Change your quotes from ' to " surrounding your query;

$query = "INSERT INTO `user` (`id`, `name`, `password`, `char_name`) VALUES (NULL, '$name', '$pass', 'test')";

Thank you, it works exactly how it should now. I appreciate the help bud!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.