0

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.

3
  • You are mixing PHP and SQL. MySQL only understand the SQL part and you are trying to force PHP down its throat. Separate your SQL from the PHP Commented Oct 29, 2012 at 22:39
  • @bikedorkseattle: He is. Please read carefully. Commented Oct 29, 2012 at 22:51
  • @MatM yeah I am noticing it now that the title has been changed. My bad :) Commented Oct 29, 2012 at 22:52

2 Answers 2

1

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)

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.