Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    T_CONSTANT_ENCAPSED_STRING question (simple)

    Im very new to PHP and MySQL, but im trying to do a simple database and login for users. The code i use is:

    Code:
    <?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:
    Code:
    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

  • #2
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts
    It's because you are using single quotes inside single quotes...

    Try this instead:

    PHP Code:
    <?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';
    ?>

  • #3
    New to the CF scene
    Join Date
    Sep 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •