Jump to content

First day of PHP, please help..


duncanhall

Recommended Posts

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]
<?php
require_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.
Link to comment
https://forums.phpfreaks.com/topic/17257-first-day-of-php-please-help/
Share on other sites

<?php
require_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")


Regards
Liam
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.