CodeIgniter Forums
Need Help with this Query - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Need Help with this Query (/showthread.php?tid=27278)



Need Help with this Query - El Forum - 02-05-2010

[eluser]mlage[/eluser]
I'm writing a registration script and have run into a problem... my query syntax. My error:

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 'WHERE NOT EXISTS (SELECT * F' at line 3

INSERT INTO users (email, password, username) VALUES ('[email protected]', 'jesuit', 'test1') WHERE NOT EXISTS (SELECT * FROM users Where username = 'test1' LIMIT 1)

Any help will be greatly appreciated!


Need Help with this Query - El Forum - 02-05-2010

[eluser]mah0001[/eluser]
You insert query is incorrect. Try something:
Code:
INSERT INTO users(email,password,username)  SELECT 'test1','test','test1' FROM DUAL WHERE NOT EXISTS (SELECT * FROM users WHERE username='test1');



Need Help with this Query - El Forum - 02-06-2010

[eluser]mlage[/eluser]
Thanks for your help. I ended up doing two separate queries to get what I wanted.