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
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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.