Mysql Create Table

Joined: 11/28/2008

I'm trying to create a table through MySQL but it's not working. Any tips?

CODE
<?php
    include('../config.php');
    if($_POST){
        mysql_query("
            CREATE TABLE users (
                ID INT(6) AUTO_INCREMENT PRIMARY KEY,
                Username VARCHAR(30),
                Password VARCHAR(30),
                FirstName VARCHAR(30),
                LastName VARCHAR(30),
                Email VARCHAR(30)
            )
            
            CREATE TABLE admin (
                Username VARCHAR(30),
                Password VARCHAR(30),
                Email VARCHAR(60),
            )
        ");
    }
    
?>
Joined: 11/28/2008
In order to manipulate or

In order to manipulate or read data, SQL has statements. Statements are anything and everything that will manipulate or read data from a database, regardless of the type of SQL database. Every statement, or query, has to be executed individually. The way SQL does this is to have each statement end with a semicolon. What you're trying to do is execute two separate statements as a singular one. Place a semicolon at the end of each CREATE TABLE statement's instance of ) and you should be good to go. Here's a trimmed example:

CODE
mysql_query("
    CREATE TABLE users ();
    CREATE TABLE admin ();
");

Who can bring a charge to God's elect? It is God who justifies!

Joined: 11/28/2008
Just one other note: most

Just one other note: most shared hosts don't allow you to create databases yourself from PHP - you have to do it from the web control panel

Paul Davey
Whitford Church
"Everyone who calls on the name of the Lord will be saved." Romans 10:13
"For all have sinned and fall short of the glory of God, and are justified

Joined: 11/28/2008
Also, the last row in your

Also, the last row in your second create statement ends in a comma (EMAIL Varchar(60), ) - which, as the last line, it shouldn't have.

Odd that you create the tables if there is *anything* in the post array - I'd certainly set some sort of semaphore so that you know that the request came from the correct page, and perhaps also consider what to do if the tables already exist - do you drop them, or just die with an error message, or be more sophisticated about it?

Regards,

Pete.

Peter Connolly
Technical Director
KP Direction LLC
http://www.kpdirection.com
http://www.kids-faith.com