0

my code is messing up. help:

        if (mysql_query("CREATE DATABASE $dbname",$con))
        {
            echo "Database Created<br>";

            $dbase = $_POST["CallSign"]."char";

            mysql_select_db($dbase, $con);

            $sql = "SELECT * FROM $dbase";

            $result = mysql_query($sql);

            if ($result)

            {
                echo "CallSign Accepted<br>";

                mysql_select_db("my_db", $con);

                $sql="INSERT INTO users 
                (
                CallSign, 
                Email, 
                FirstName, 
                MiddleName, 
                LastName, 
                Gender, 
                BirthMonth, 
                BirthDay, 
                BirthYear, 
                Location, 
                Password,
                Origin,
                ) VALUES 
                (
                '$_POST[CallSign]',
                '$_POST[Email]',
                '$_POST[FirstName]',
                '$_POST[MiddleName]',
                '$_POST[LastName]',
                '$_POST[Gender]',
                '$_POST[BirthMonth]',
                '$_POST[BirthDay]',
                '$_POST[BirthYear]',
                '$_POST[Location]',
                '$_POST[Password1]',
                Now()
                )";

                if (mysql_query($sql,$con))
                {
                    echo "Values Posted<br>";

                    $dbase = $_POST["CallSign"]."char";

                    mysql_select_db($dbase, $con);

                    $sql = "CREATE TABLE chars 
                    (
                    charID int NOT NULL AUTO_INCREMENT,
                    PRIMARY KEY(charID),
                    CharName varchar(15),
                    CharPub TEXT,
                    CharPriv TEXT,
                    CharGame int DEFAULT '0', 
                    CharBorn TIMESTAMP DEFAULT NOW()
                    )";

                    if (!mysql_query($sql,$con))
                    {
                        die('Error: ' . mysql_error());
                    }
                    else
                    {
                        echo "Account Created";
                        echo "<p><a href='index.php'>Return to Login</a>";
                    }

                }
                else
                {
                    $dbase = $_POST["CallSign"]."char";

                    mysql_select_db($dbase, $con);

                    $sql = "CREATE TABLE chars 
                    (
                    charID int NOT NULL AUTO_INCREMENT,
                    PRIMARY KEY(charID),
                    CharName varchar(15),
                    CharPub TEXT,
                    CharPriv TEXT,
                    CharGame int DEFAULT '0', 
                    CharBorn TIMESTAMP DEFAULT NOW()
                    )";

                    if (!mysql_query($sql,$con))
                    {
                        die('Error: ' . mysql_error());
                    }
                    else
                    {
                        echo "Callsign Reguested<br>Database Created<br>Tables Organized<br>Cajun Style<p>";
                        echo "Account Created";
                        echo "<p><a href='index.php'>Return to Login</a>";
                    }
2
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by da(code)da
0

At line 9 I see this string:

$sql = "SELECT * FROM $dbase";

so you have a table with the same name of the database? I ask this because it seems your script expects a true condition from $result variable in the IF statement at line 13, so I suggest you to change line 11 with this:

$result = mysql_query($sql) or die(mysql_error());

and check if you get an error or false.

Edited by cereal

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.