3 Replies - 1601 Views - Last Post: 17 April 2010 - 09:31 AM Rate Topic: -----

#1 BlackVenom  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 16-April 10

Can't create a MySQL table

Posted 16 April 2010 - 09:47 PM

I've been trying to pass this through for quite a bit but I can't figure out what's wrong.

mysql_query("CREATE TABLE scMain(
id INT NOT NULL AUTO_INCREMENT, 
PRIMARY KEY(id),
scuser VARCHAR(20), 
scmsg VARCHAR(90)")
 or die(mysql_error());



I get the 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 '' at line 5". Which makes me assume it's the the line with scmsg VARCHAR(90)"). I've tried multiple variants of this code w/ no success in creating a table.

This post has been edited by BlackVenom: 17 April 2010 - 09:32 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Can't create a MySQL table

#2 atik97  Icon User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Re: Can't create a MySQL table

Posted 16 April 2010 - 10:14 PM

Here is the corrected sql syntax-
CREATE TABLE scMain(
id INT NOT NULL AUTO_INCREMENT ,
PRIMARY KEY ( id ) ,
scuser VARCHAR( 20 ) ,
scmsg VARCHAR( 90 )
);


What you have done is missing the closing ')' which was generating an error.
Was This Post Helpful? 0
  • +
  • -

#3 Fratyr  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 139
  • Joined: 10-April 08

Re: Can't create a MySQL table

Posted 17 April 2010 - 05:56 AM

BlackVenom,

To avoid SQL errors, I would recommend to use/test your queries in PhpMyAdmin application, It's more comfortable than trying to execute SQL query through PHP without a lot of experience in SQL syntax.
Was This Post Helpful? 0
  • +
  • -

#4 BlackVenom  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 16-April 10

Re: Can't create a MySQL table

Posted 17 April 2010 - 09:31 AM

Ah, thanks! I figured it was one little detail... and thanks for the tip Fratyr.

EDIT: Doesn't work; here's the full code this time.

<?php
// connect
mysql_connect("localhost", "USER", "PASS") or die(mysql_error());
mysql_select_db("scriptc_sctst") or die(mysql_error());

// create
mysql_query("CREATE TABLE scMain
(
    id INT NOT NULL AUTO_INCREMENT, 
    PRIMARY KEY(id),
    scuser VARCHAR(20), 
    scmsg VARCHAR(90)"
))
 or die(mysql_error());  

echo "Table Created!";

?>


THat gives me "Parse error: syntax error, unexpected ')' in mysqt.php on line 12"


EDIT: success...

mysql_query("CREATE TABLE scMain(
id INT NOT NULL AUTO_INCREMENT ,
PRIMARY KEY ( id ) ,
scuser VARCHAR( 20 ) ,
scmsg VARCHAR( 90 )
)")
 or die(mysql_error()); 

This post has been edited by BlackVenom: 17 April 2010 - 10:04 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1