Results 1 to 4 of 4

Thread: [RESOLVED] Create table not working!

  1. #1

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Resolved [RESOLVED] Create table not working!

    Hi,

    I'm using code I have used before to create a database! While I can create the database for some reason it won't allow me to create the table. This is the code I am using to create the database:

    PHP Code:
    <?php
    //connect to server or exit
    require_once("php/conroot.php");

    //create database
    $query "CREATE DATABASE IF NOT EXISTS $dbDatabase";
    if (
    mysql_query($query$conn)) {
    echo (
    "Database create query successful");
    }
    //select database
    if (mysql_select_db($dbDatabase$conn)) {
    echo (
    "Database selection successful");
    }else {
    die (
    "Could not locate $dbDatabase database" .mysql_error());
    }

    //create table
    $query "CREATE TABLE IF NOT EXISTS $table  (
    'id' int(2) NOT NULL auto_increment unique,
      'Nameochild' varchar(30) default NULL,
      'Address' varchar(30) default NULL,
      'Email' varchar(50) default NULL,
      'Mobile' varchar(20) default NULL,
      'Postcode' varchar(6) default NULL,
      DOB' varchar(20) default NULL,
      'Phone' varchar(10) default NULL,
      'Medical' varchar(100) default NULL,
      'Photo' varchar(1) default NULL,
      'Guardian' varchar(20) default NULL,
       'Date'(8) default NULL,
      PRIMARY KEY  ('id')
    ) TYPE=MyISAM"
    ;


    if (
    mysql_query($query$conn)) {
    echo (
    "table $table query successful");
    }
    ?>
    Edit:

    Here is the code for conroot.php:

    PHP Code:
    <?php
    //connect to db
    $conn mysql_connect("localhost""root""");
    if (!
    $conn) {
    die(
    "Connection failed: " .mysql_error());
    }
    // Database connection variables
    $dbDatabase "database";
    $table "table";
    ?>
    Have I missed anything? I have looked over the code and cant see anything that might be wrong.


    Thanks,


    Nightwalker
    Last edited by Nightwalker83; Feb 20th, 2010 at 01:31 AM. Reason: Adding more
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  2. #2
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Create table not working!

    I ran your query though phpMyAdmin. It gave this error:
    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''id' int(2) NOT NULL auto_increment unique, 'Nameochild' varchar(30) default ' at line 2
    Use ` instead of ' , should work

  3. #3
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Create table not working!

    There are some format issues as well. You should proofread your query. To debug your code use something like this:

    PHP Code:
    mysql_query($query$conn) or die(mysql_error()); 

  4. #4

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Create table not working!

    I changed:

    PHP Code:
     'Date'(8) default NULL
    to

    PHP Code:
    Date varchar(8) default NULL
    Thanks for the help! That solved the problem.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

Posting Permissions

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



Click Here to Expand Forum to Full Width