Jump to content

Archived

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

duncanhall

First day of PHP, please help..

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.

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

×

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.