Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10

Thread: newbie question

  1. #1
    Regular Coder
    Join Date
    Aug 2005
    Posts
    279
    Thanks
    0
    Thanked 0 Times in 0 Posts

    newbie question

    Hi I tried to create a table called member in my databased called "default" that is provided by my webhost, which means I'm limited to use only that database. I have this code below, but it does not work. Any idea what's wrong with it?

    PHP Code:

    <? php
    include 'config.php';
    include 
    'opendb.php';

    // create the member table and fields

    $query 'CREATE TABLE member ( '.
                
    // fields
                
    'mid INT NOT NULL AUTO_INCREMENT, '.
                
    'mfname VARCHAR(20) NOT NULL, '.
                
    'mlname VARCHAR(20) NOT NULL, '.
                
    'memail VARCHAR(60) NOT NULL, '.
                
    'PRIMARY KEY(mid)
              )'
    ;

    $result mysql_query($query);

    include 
    'closedb.php';
    ?>

  • #2
    New Coder
    Join Date
    Feb 2006
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    do you have PHPmyAdmin?

  • #3
    Regular Coder
    Join Date
    Aug 2005
    Posts
    279
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah I do but I want to try out using sql to create table... apparently I didn't succeed.

  • #4
    New Coder
    Join Date
    Feb 2006
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hmmm, sorry. i'm lazy i guess you could say, and just PHPmyAdmin.
    -cnelson.

  • #5
    Regular Coder
    Join Date
    Feb 2005
    Location
    Tokyo, Japan
    Posts
    151
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this...

    I've included an "if" statment that will tell you if the table has been created or not. In the event there is a problem with your MySQL syntax, it will display the error.

    PHP Code:
    <? php
    include 'config.php';
    include 
    'opendb.php';

    // create the member table and fields

    $query 'CREATE TABLE member ( '.
                
    // fields
                
    'mid INT NOT NULL AUTO_INCREMENT, '.
                
    'mfname VARCHAR(20) NOT NULL, '.
                
    'mlname VARCHAR(20) NOT NULL, '.
                
    'memail VARCHAR(60) NOT NULL, '.
                
    'PRIMARY KEY(mid)
              )'




    if( 
    mysql_query$query ) )
        echo( 
    "Table created successfully.<br>" );
    else
        die( 
    "Error! Could not create table: " mysql_error() );

    As for the Query I would have done this*
    PHP Code:
    $query "CREATE TABLE member ( 
                mid INT NOT NULL AUTO_INCREMENT, 
                mfname VARCHAR(20) NOT NULL, 
                mlname VARCHAR(20) NOT NULL, 
                memail VARCHAR(60) NOT NULL, 
                PRIMARY KEY(mid)
              )"


    if( 
    mysql_query$query ) )
        echo( 
    "Table created successfully.<br>" );
    else
        die( 
    "Error! Could not create table: " mysql_error() ); 
    (*note the quotes)
    not tested, but it should work.

    Hope that helps...

    Yakisoba

  • #6
    Regular Coder
    Join Date
    Aug 2005
    Posts
    279
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It said nothing... still blank page...

  • #7
    Regular Coder
    Join Date
    Aug 2005
    Posts
    279
    Thanks
    0
    Thanked 0 Times in 0 Posts
    problem solved,

    Thanks for helping

  • #8
    Regular Coder
    Join Date
    Aug 2005
    Posts
    279
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Is there a way to put the error notification code on php? Sometimes the page display without knowing what's going wrong. any idea?

  • #9
    Regular Coder
    Join Date
    Feb 2005
    Location
    Tokyo, Japan
    Posts
    151
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Not sure what your question is.
    PHP Code:
     mysql_error() 
    is a php function.


    What did you do to solve your first problem?

    Yakisoba

  • #10
    Regular Coder
    Join Date
    Aug 2005
    Posts
    279
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Did you notice there is a space after
    <? php ... php is so picky, I need to change to <?php (no space)
    that's the problem


  •  

    Posting Permissions

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