www.webdeveloper.com
Results 1 to 6 of 6

Thread: database creation issues

  1. #1
    Join Date
    Jan 2006
    Posts
    88

    database creation issues

    I'm new to sql so this might be obvious to you
    PHP Code:
    <?php
    $connid 
    = @mysql_connect ('localhost' 'masc' 'glumph');
    if (
    $connid == false)
     { print 
    "Server connection failed";  }
    else
     { print 
    "Server connected!"; }
    $query="CREATE TABLE meminfo(
    userid INT IDENTITY(1,1) NOT NULL,
    username CHAR(20) NULL,
    password CHAR(20) NULL)"
    ;

    $result=mysql_query ($query) or die("ERROR: " .mysql_error());;

    $query="INSERT INTO meminfo(username,password)
    VALUES('Paul', 'Kloos')"
    ;

    $result=mysql_query($query) or die("ERROR: " .mysql_error());;

    $query="SELECT *";

    $result=mysql_query($query) or die("ERROR: " .mysql_error());

    echo 
    $result;
    ?>
    and the error is
    Code:
    Server connected!ERROR: 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 'IDENTITY(1,1) NOT NULL, username CHAR(20) NULL, password CHAR(20) NULL)' at line 2
    and what i got from my php info from the server i'm on is
    Client API version 4.1.7

    so, i don't know what to do, i'm just using examples i found on this htmlgoodies

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,400
    I am not aware of any IDENTITY() attribute for integers in MySQL.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jan 2006
    Posts
    88
    Next we use IDENTITY which tells the DBMS that this is our Primary Key.Now, the (1,1) means that we want to start with the number 1 and we want to increment each new ID number by 1.
    this is from the sql tutorial at htmlgoodies.com http://www.htmlgoodies.com/primers/d...le.php/3478061

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,400
    PHP Code:
    $query="CREATE TABLE meminfo(
    userid INT PRIMARY KEY AUTO_INCREMENT,
    username CHAR(20) NULL,
    `password` CHAR(20) NULL) AUTO_INCREMENT=1"

    Also, I would suggest that username and password should be NOT NULL. Lastly, "password" is a reserved word in MySQL, so you'll need to back-tick it in your queries when being used as a column name.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Jan 2006
    Posts
    88
    Actually now I'm getting
    Code:
    Server connected!ERROR: No database selected
    well the fact that i'm clueless about this one shows what a noob i am.
    PHP Code:
    $query="SELECT * FROM meminfo"
    this is the code i'm trying. but to stop some of these stupid questions, can someone direct me to a good mysql tutorial because I don't want to bother you guys too much.

  6. #6
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    after you connect, you need to select your database using the php command
    PHP Code:
    mysql_select_db($database_name); 
    Also, the link you posted is for a MS Access tutorial. You need mysql tutorials.

    How about this one:
    http://www.freewebmasterhelp.com/tutorials/phpmysql/
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles