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 13 of 13
  1. #1
    Regular Coder googleit's Avatar
    Join Date
    Jul 2006
    Location
    birmingham, uk
    Posts
    189
    Thanks
    0
    Thanked 0 Times in 0 Posts

    what is wrong with this code?

    i get an error saying
    Code:
    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 ' email VARCHAR' at line 5
    when i run this code

    PHP Code:
    mysql_connect("host""username""passwd") or die(mysql_error());
    mysql_select_db("dbname) or die(mysql_error());

    mysql_query("
    CREATE TABLE example(
    id INT NOT NULL AUTO_INCREMENT
    PRIMARY KEY(id),
     
    name VARCHAR(30), 
     
    comments VARCHAR,
     
    email VARCHAR")
     or die(mysql_error());  

    echo "
    Table Created!"; 
    why do i get this error?

  • #2
    New Coder
    Join Date
    Aug 2006
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the email & comment VARCHAR should have a value ie 25 ( for 25 character

    PRIMARY KEY(id),
    name VARCHAR(30),
    comments VARCHAR(22),
    email VARCHAR(22") limit )


    replace 22 with teh amount of characters ( letters ) you want in that value

  • #3
    New Coder
    Join Date
    Aug 2006
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    because email isnt set to UNIQUE you could even replace VARCHAR with TEXT ( no value required )

    so use either

    mysql_query("CREATE TABLE example(
    id INT NOT NULL AUTO_INCREMENT,
    PRIMARY KEY(id),
    name VARCHAR(30),
    comments VARCHAR(22),
    email VARCHAR(22)")
    or die(mysql_error());

    or

    mysql_query("CREATE TABLE example(
    id INT NOT NULL AUTO_INCREMENT,
    PRIMARY KEY(id),
    name VARCHAR(30),
    comments TEXT,
    email TEXT")
    or die(mysql_error());

  • #4
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    you're missing a closing " on the select_db line (though possibly a typo while deleting the real dbname...)
    and also a closing bracket inside the create table query.

  • #5
    Regular Coder googleit's Avatar
    Join Date
    Jul 2006
    Location
    birmingham, uk
    Posts
    189
    Thanks
    0
    Thanked 0 Times in 0 Posts
    got this error this time
    Code:
    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 '' at line 6

  • #6
    Regular Coder googleit's Avatar
    Join Date
    Jul 2006
    Location
    birmingham, uk
    Posts
    189
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Gjay i got this error
    Code:
    Parse error: parse error, unexpected T_STRING in /home/content/b/r/a/bradley/html/create.php on line 7

  • #7
    New Coder
    Join Date
    Aug 2006
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    mysql_select_db("dbname) or die(mysql_error());

    Change to

    mysql_select_db("dbname") or die(mysql_error());

  • #8
    New Coder
    Join Date
    Aug 2006
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    change EVERYTHING to

    PHP Code:
    mysql_connect("host""username""passwd") or die(mysql_error()); 
    mysql_select_db("dbname") or die(mysql_error()); 

    mysql_query("CREATE TABLE example( 
    id INT NOT NULL AUTO_INCREMENT,  
    PRIMARY KEY(id), 
     name VARCHAR(30),  
     comments text, 
     email text"

     or die(
    mysql_error());   

    echo 
    "Table Created!"

  • #9
    Regular Coder googleit's Avatar
    Join Date
    Jul 2006
    Location
    birmingham, uk
    Posts
    189
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeah i have still get the error tho

  • #10
    New Coder
    Join Date
    Aug 2006
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    is that code at the top of the php page ?

    trying to determine what line 6 is

    i think its the INT.. try this

    mysql_connect("host", "username", "passwd") or die(mysql_error());
    mysql_select_db("dbname") or die(mysql_error());

    mysql_query("CREATE TABLE example(
    id INT(10) NOT NULL AUTO_INCREMENT,
    PRIMARY KEY(id),
    name VARCHAR(30),
    comments text,
    email text")
    or die(mysql_error());

    echo "Table Created!";


    that gives your id the possibility of 10 digits

  • #11
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    the closing bracket is still missing...

  • #12
    New Coder
    Join Date
    Aug 2006
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ahh yes after the email TEXT")
    need


    email TEXT"))

  • #13
    Regular Coder googleit's Avatar
    Join Date
    Jul 2006
    Location
    birmingham, uk
    Posts
    189
    Thanks
    0
    Thanked 0 Times in 0 Posts
    finally! gjay & managedinternet thanks for your time.
    it was the closing bracket


  •  

    Posting Permissions

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