Daniel o keeffe
Daniel o keeffe

Reputation: 51

SQL query into phpmyadmin - error in syntax

I'm trying to create an email validation for user registration.

I am following step by step instructions but i am bogged down in something that should be quite simple.

I am supposed to insert the following into a database using a MySql query:

mysql_query("INSERT INTO users (username, password, email, hash) VALUES(
'". mysql_escape_string($name) ."',
'". mysql_escape_string(md5($password)) ."',
'". mysql_escape_string($email) ."',
'". mysql_escape_string($hash) ."') ") or die(mysql_error()); 

I am using WAMP server. I went to my database, selected the table, inserted the above after selecting the SQL tab, clicked go and got the response:

"#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql_query("INSERT INTO users (username, password, email, hash) VALUES( '". m' at line 1"

I can never seem to insert queries into the phpMyAdmin databases without getting some sort of error. I'm hoping someone can shed some light on this to give me an outside view.

Needless to say, i would be grateful for any input. I am new to this and at my wits end.

Upvotes: 0

Views: 829

Answers (2)

Mat M
Mat M

Reputation: 1884

As Prash said, mysql_query and mysql_escape_string are php functions beside their names. When pasting into the SQL tab of phpMyAdmin, you should remove the mysql_query() which represents PHP call to MySQL db and convert mysql_escape_string calls to the computed values of variables ($...). It should give you something like:

INSERT INTO users (username, password, email, hash) VALUES(
'SampleName',
md5('SamplePassword'),
'[email protected]',
'SampleHash') 

You need to escape by yourself if there are special chars in values)

Upvotes: 1

purpletree
purpletree

Reputation: 1943

You can't use PHP functions in SQL. Run the PHP code instead

Upvotes: 1

Related Questions