duncanhall Posted August 11, 2006 Share Posted August 11, 2006 So today I decided to make "the switch" from .NET to PHP and, being very new, need a little help.I have been following a simple tutorial to create a login/out page with a MySQL database. I have a "create_table.php" page which returns the following error:[b]Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING on line 6[/b]the code is:[code]<?phprequire_once('connect.php');mysql_query('CREATE TABLE `users` (`id` int(11) NOT NULL auto_increment,`username` varchar(20) NOT NULL default '',`password` varchar(32) NOT NULL default '',`date_registered` int(10) NOT NULL default '0',`last_seen` int(10) NOT NULL default '0',PRIMARY KEY (`id`))');echo 'Table created';?>[/code]Any help on this would be most appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/17257-first-day-of-php-please-help/ Share on other sites More sharing options...
shocker-z Posted August 11, 2006 Share Posted August 11, 2006 <?phprequire_once('connect.php');mysql_query("CREATE TABLE `users` (`id` int(11) NOT NULL auto_increment,`username` varchar(20) NOT NULL default '',`password` varchar(32) NOT NULL default '',`date_registered` int(10) NOT NULL default '0',`last_seen` int(10) NOT NULL default '0',PRIMARY KEY (`id`))");echo 'Table created';?>give that a blast mate :)i just changed mysql_query('your statement') to mysql_query("'your statement")RegardsLiam Quote Link to comment https://forums.phpfreaks.com/topic/17257-first-day-of-php-please-help/#findComment-73150 Share on other sites More sharing options...
Ninjakreborn Posted August 11, 2006 Share Posted August 11, 2006 You are starting off getting bad habits, it's ALWAYS safer to run your query's through a variable, and allows for easier changes and error handling.Learning sql this way is good but you will NEVER have a purpose to use something like this in a live application, creating tables on the fly in an application can be dangerous, and after awhile you get enough tables it starts to kill the database. If you are wanting to learn sql syntax, use a program, so it can tell you where your syntax errors are located when you are in sql prompt. Quote Link to comment https://forums.phpfreaks.com/topic/17257-first-day-of-php-please-help/#findComment-73153 Share on other sites More sharing options...
duncanhall Posted August 11, 2006 Author Share Posted August 11, 2006 Cheers Liam, that worked!businessman, would you mind elaborating on "It's ALWAYS safer to run your query's through a variable"?Would you suggest using phpMyAdmin to configure my tables? Quote Link to comment https://forums.phpfreaks.com/topic/17257-first-day-of-php-please-help/#findComment-73158 Share on other sites More sharing options...
High_-_Tek Posted August 11, 2006 Share Posted August 11, 2006 No,buisnessman in saying that you want to assign the query to a variable, and then set that variable as the mysql_query string as so:[code]$q = "SELECT * FROM table";$result = mysql_query($q);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17257-first-day-of-php-please-help/#findComment-73172 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.