Results 1 to 9 of 9

Thread: Creating a mysql table with php

  1. #1
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Creating a mysql table with php

    How do I make a PHP file creat this table in mysql. If I put this directly into sql it creats the table but I want a php file to do it by running it in the browser.
    PHP Code:
    <?php 
    CREATE  TABLE  
    `wichita_frgn1`.`Registrations` (  `idint10  )  unsigned NOT  NULL  auto_increment 
    `
    First_Nametext NOT  NULL 
    `
    Last_Nametext NOT  NULL 
    `
    Addresstext NOT  NULL 
    `
    Citytext NOT  NULL 
    `
    Statetext NOT  NULL 
    `
    Zip_Codetext NOT  NULL 
    `
    Home_Phonetext NOT  NULL 
    `
    Cell_Phonetext NOT  NULL 
    `
    E_Mailtext NOT  NULL 
    `
    Membership_Notext NOT  NULL 
    `
    Roar_Notext NOT  NULL 
    `
    First_Classtext NOT  NULL 
    `
    Transmitter_Frequencytext NOT  NULL 
    `
    Transponder_Notext NOT  NULL 
    `
    Track_Transpondertext NOT  NULL 
    `
    Second_Classtext NOT  NULL 
    `
    Transmitter_Frequency2text NOT  NULL 
    `
    Transponder_No2text NOT  NULL 
    `
    Track_Transponder2text NOT  NULL 
    `
    Ability_Skill_Leveltext NOT  NULL 
    `
    Race_Datedate NOT  NULL default  '0000-00-00'
    `
    Tracktext NOT  NULL 
    `
    IP_Addresstext NOT  NULL 
    `
    Date_Postedtext NOT  NULL 
    PRIMARY  KEY (  `id`  ) , 
    UNIQUE  KEY  `id_2` (  `id`  ) , 
    KEY  `id` (  `id`  )  ) ENGINE  =  MyISAM  DEFAULT CHARSET  latin1 COMMENT  =  'Created by Big-Dog; 
    ?>

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    PHP Code:
    <?php
    $host 
    'localhost'//or url
    $user 'me';
    $pass 'pass'//note this is secure on your server in the php file
    $conn mysql_connect($host,$user,$pass);
    $query 'CREATE TABLE .... STUFF';
    mysql_query($query);
    ?>
    http://www.php.net/manual/en/function.mysql-connect.php
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I get this error
    Parse error: syntax error, unexpected T_LNUMBER in /home/public_html/Registration/creattable.php on line 28
    which is `Race_Date` date NOT NULL default '0000-00-00',
    PHP Code:
    <?php
    $username
    ="MYUSER";
    $password="MYPASS";
    $database="MYDB";

    $conn mysql_connect(localhost,$username,$password);
    $query 'CREATE  TABLE  `wichita_frgn`.`Registrations` (  `id` int( 10  )  unsigned NOT  NULL  auto_increment , 
    `First_Name` text NOT  NULL , 
    `Last_Name` text NOT  NULL , 
    `Address` text NOT  NULL , 
    `City` text NOT  NULL , 
    `State` text NOT  NULL , 
    `Zip_Code` text NOT  NULL , 
    `Home_Phone` text NOT  NULL , 
    `Cell_Phone` text NOT  NULL , 
    `E_Mail` text NOT  NULL , 
    `Membership_No` text NOT  NULL , 
    `Roar_No` text NOT  NULL , 
    `First_Class` text NOT  NULL , 
    `Transmitter_Frequency` text NOT  NULL , 
    `Transponder_No` text NOT  NULL , 
    `Track_Transponder` text NOT  NULL , 
    `Second_Class` text NOT  NULL , 
    `Transmitter_Frequency2` text NOT  NULL , 
    `Transponder_No2` text NOT  NULL , 
    `Track_Transponder2` text NOT  NULL , 
    `Ability_Skill_Level` text NOT  NULL , 
    `Race_Date` date NOT  NULL default  '
    0000-00-00',
    `Track` text NOT  NULL , 
    `IP_Address` text NOT  NULL , 
    `Date_Posted` text NOT  NULL , 
    PRIMARY  KEY (  `id`  ) , 
    UNIQUE  KEY  `id_2` (  `id`  ) , 
    KEY  `id` (  `id`  )  ) ENGINE  =  MyISAM  DEFAULT CHARSET  = latin1 COMMENT  =  '
    Created by big dog'
    '
    ;
    mysql_query($query);
    ?>

    [MOD EDIT: DO NOT POST SENSITIVE DATA!! Removed. We don't need the exact password, etc. to help you and it is a HUGE security risk...]
    Last edited by djr33; 10-04-2007 at 04:34 AM.

  4. #4
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    You need to escape the quotes first.

    PHP Code:
    <?php
    $username
    ="*****************"//Replace the asterisks with your username.
    $password="*****************"//Replace the asterisks with your password.
    $database="*****************"//Replace the asterisks with your database.

    $conn mysql_connect(localhost,$username,$password);
    $query 'CREATE  TABLE  `wichita_frgn`.`Registrations` (  `id` int( 10  )  unsigned NOT  NULL  auto_increment , 
    `First_Name` text NOT  NULL , 
    `Last_Name` text NOT  NULL , 
    `Address` text NOT  NULL , 
    `City` text NOT  NULL , 
    `State` text NOT  NULL , 
    `Zip_Code` text NOT  NULL , 
    `Home_Phone` text NOT  NULL , 
    `Cell_Phone` text NOT  NULL , 
    `E_Mail` text NOT  NULL , 
    `Membership_No` text NOT  NULL , 
    `Roar_No` text NOT  NULL , 
    `First_Class` text NOT  NULL , 
    `Transmitter_Frequency` text NOT  NULL , 
    `Transponder_No` text NOT  NULL , 
    `Track_Transponder` text NOT  NULL , 
    `Second_Class` text NOT  NULL , 
    `Transmitter_Frequency2` text NOT  NULL , 
    `Transponder_No2` text NOT  NULL , 
    `Track_Transponder2` text NOT  NULL , 
    `Ability_Skill_Level` text NOT  NULL , 
    `Race_Date` date NOT  NULL default \'0000-00-00\',
    `Track` text NOT  NULL , 
    `IP_Address` text NOT  NULL , 
    `Date_Posted` text NOT  NULL , 
    PRIMARY  KEY (  `id`  ) , 
    UNIQUE  KEY  `id_2` (  `id`  ) , 
    KEY  `id` (  `id`  )  ) ENGINE  =  MyISAM  DEFAULT CHARSET  = latin1 COMMENT  =  '
    Created by big dog'
    '
    ;
    mysql_query($query);
    ?>
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You must escape quotes of the same type as those surrounding the string, ie:

    'don\'t';

    Add a backslash before those offending quotes around the 00-000-00 thing.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    now I get
    Parse error: syntax error, unexpected T_STRING in /home/public_html/Registration/creattable.php on line 34
    which is
    KEY `id` ( `id` ) ) ENGINE = MyISAM DEFAULT CHARSET = latin1 COMMENT = 'Created by big dog'

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    That line needs to be escaped as well.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Perfect for a heredoc:
    Code:
    $query = <<<EOQ
    CREATE  TABLE
    `wichita_frgn1`.`Registrations` (
      `id` int( 10  )  unsigned NOT  NULL  auto_increment,
      `First_Name` text NOT  NULL,
      `Last_Name` text NOT  NULL,
      `Address` text NOT  NULL,
      `City` text NOT  NULL,
      `State` text NOT  NULL,
      `Zip_Code` text NOT  NULL,
      `Home_Phone` text NOT  NULL,
      `Cell_Phone` text NOT  NULL,
      `E_Mail` text NOT  NULL,
      `Membership_No` text NOT  NULL,
      `Roar_No` text NOT  NULL,
      `First_Class` text NOT  NULL,
      `Transmitter_Frequency` text NOT  NULL,
      `Transponder_No` text NOT  NULL,
      `Track_Transponder` text NOT  NULL,
      `Second_Class` text NOT  NULL,
      `Transmitter_Frequency2` text NOT  NULL,
      `Transponder_No2` text NOT  NULL,
      `Track_Transponder2` text NOT  NULL,
      `Ability_Skill_Level` text NOT  NULL,
      `Race_Date` date NOT  NULL default  '0000-00-00',
      `Track` text NOT  NULL,
      `IP_Address` text NOT  NULL,
      `Date_Posted` text NOT  NULL,
      PRIMARY  KEY (  `id`  ),
      UNIQUE  KEY  `id_2` (  `id`  ),
      KEY  `id` (  `id`  )
    )
    ENGINE  =  MyISAM
    DEFAULT CHARSET  = latin1
    COMMENT  =  'Created by Big-Dog'
    EOQ;
    ?>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    THANKS
    I got it to work

Bookmarks

Posting Permissions

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