Results 1 to 3 of 3

Thread: PHP ')' error. line 4

  1. #1
    Join Date
    Apr 2005
    Posts
    2

    Question PHP ')' error. line 4

    It says I have an error at line 4. Sorry to say thats all I know. Anyone know how i can fix or clean up this script?


    PHP Code:
    <?php $dbconnection = @mysql_connect(localhostadminpassword);

    if (!
    $dbconnection) {
      echo( 
    "<p>Unable to connect to the " "database server at this time.</p>" );
      exit();
    }

    if (! @
    mysql_select_db("database") ) {
      echo( 
    "<p>Unable to locate the joke " .
            
    "database at this time.</p>" );
      exit();
    }
    $user=$_POST['name'];

    if (!
    $_POST['name']) {
      echo( 
    "<p>please submit form" );
    }else{
    $sql "CREATE TABLE $user (
             ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
             
    $user TEXT,
           )"
    ;
    if ( @
    mysql_query($sql) ) {
      echo(
    "<p>".$user." table successfully created!</p>");
    } else {
      echo(
    "<p>Error creating ".$user." table: " mysql_error() . "</p>");
    }
    }
    ?>

    <form method="post" action="newsite.php">
    Enter your name: <input type="text" name="name">
    <input type="submit" value="done!">
    </form>
    If input field "name" is blank. i want it to do nothing. if it has input in the field i want it to create a table in the database called whatever the input is.

    Thanks,
    Tyler

  2. #2
    Join Date
    Apr 2005
    Location
    florida
    Posts
    89
    $sql = "CREATE TABLE $user (
    ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    $user TEXT,
    )";

    1) you put a "," at the end of the script. ($user TEXT,). Fix this

    2) I would do it like this:

    $sql = "CREATE TABLE ".$user." ( ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, ".$user." TEXT)";

    in one single line and "space" after each word

    Good luck...

  3. #3
    Join Date
    Apr 2005
    Posts
    2
    thanks alot. works like a charm.

Posting Permissions

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