...

View Full Version : T_CONSTANT_ENCAPSED_STRING question (simple)



Kokarn
09-15-2006, 11:34 AM
Im very new to PHP and MySQL, but im trying to do a simple database and login for users. The code i use is:



<?php
require_once('connect.php');
mysql_query('CREATE TABLE `users` (
`id` int(15) 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';
?>


I get an error, shown below.

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/onyttse/public_html/thursday/create_table.php on line 6

I checked around a bit, and found out that in most cases, it's just a ";" missing, so i added that to all the lines, nothing, and also removed the "," from all the lines. Still nothing.
Also tried to change all the " ` " to " ' ", all i got by doing that is another error, shown below:


Parse error: parse error, unexpected T_STRING in /home/onyttse/public_html/thursday/create_table.php on line 3


Guess thats for chaning data types or something?
So, what's my problem?

Thanks in advance // Oskar Risberg

Taylor_1978
09-15-2006, 11:39 AM
It's because you are using single quotes inside single quotes...

Try this instead:



<?php
require_once('connect.php');
mysql_query("CREATE TABLE `users` (
`id` int(15) 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';
?>

Kokarn
09-15-2006, 11:46 AM
The only thing you changed was the ' to " before CREATE TABLE and in the )') line, right? Because now it works. But i changed that manually at first, and got insane errors. Then i copied your text, and it worked.

Taylor_1978
09-15-2006, 11:50 AM
Yep, thats correct. That's all I changed.

It's possible you may have just accidentally placed it in the wrong spot when you did it yourself. We all do it, it's call being delirious from scripting for hours on end! lol



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum