Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

- - - - -

Syntax error

syntax syntax error

  • Please log in to reply
6 replies to this topic

#1 Guest_Jaan_*

Guest_Jaan_*
  • Guest

Posted 16 January 2008 - 09:34 AM

Anyway.. i have this problemo..

$CreateTables = "CREATE TABLE 'administrator' (
'uname' VARCHAR( 15 ),
'pword' VARCHAR( 15 ),
'email' VARCHAR( 50 ),
'lastlogin' VARCHAR( 25 )
)

CREATE TABLE 'files' (
'id' INT( 5 ) AUTO_INCREMENT ,
'filename' VARCHAR( 50 ),
'size' VARCHAR( 50 ),
'mime' VARCHAR( 50 ),
'created' VARCHAR( 50 ),
'lastedit' VARCHAR( 50 ),
PRIMARY KEY ( 'id' )
)

CREATE TABLE 'history' (
'id' INT( 5 ) AUTO_INCREMENT ,
'filename' VARCHAR( 50 ),
'created' VARCHAR( 50 ),
'lastedit' VARCHAR( 50 ),
'action' VARCHAR( 50 ),
PRIMARY KEY ( 'id' )
)
";
$CreateQuery = mysql_query($CreateTables);


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 ''administrator' ( 'uname' VARCHAR( 15 ), 'pword' VARCHAR( 15 ), 'email' VARCH' at line 1


i have no idea how to fix it..
maybe someone can help me :)
  • 0

#2 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 16 January 2008 - 12:40 PM

Rather than using apostrophes around the column names, try using ticks.

$CreateTables = "CREATE TABLE `administrator` (
`uname` VARCHAR( 15 ),
`pword` VARCHAR( 15 ),
`email` VARCHAR( 50 ),

  • 0

#3 Guest_Jaan_*

Guest_Jaan_*
  • Guest

Posted 16 January 2008 - 12:59 PM

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 'CREATE TABLE `files` ( `id` INT( 15 ) AUTO_INCREMENT , `filename` VARCHAR( 50 ' at line 8


$tables ="CREATE TABLE `administrator` (
`uname` VARCHAR( 15 ),
`pword` VARCHAR( 15 ),
`email` VARCHAR( 25 ),
`lastlogin` VARCHAR( 25 )
)

CREATE TABLE `files` (
`id` INT( 15 ) AUTO_INCREMENT ,
`filename` VARCHAR( 50 ),
`size` VARCHAR( 50 ),
`mime` VARCHAR( 50 ),
`created` VARCHAR( 50 ),
`lastedit` VARCHAR( 50 ),
PRIMARY KEY ( `id` )
)

CREATE TABLE `history` (
`id` INT( 15 ) AUTO_INCREMENT ,
`filename` VARCHAR( 50 ),
`created` VARCHAR( 50 ),
`lastedit` VARCHAR( 50 ),
`action` VARCHAR( 50 ),
PRIMARY KEY ( `id` )
)";

$query = mysql_query($tables);


**** nothing works.. i was discussing it with Jordan also.. and we never found any solutions..
  • 0

#4 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 16 January 2008 - 04:37 PM

ok, it took me about two hours but the answer was staring me right in the face.

mysql_query() sends an unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier .


And your SQL query should be this:
CREATE TABLE `administrator` (
`uname` VARCHAR( 15 ),
`pword` VARCHAR( 15 ),
`email` VARCHAR( 25 ),
`lastlogin` VARCHAR( 25 )
);

CREATE TABLE `files` (
`id` INT( 15 ) AUTO_INCREMENT ,
`filename` VARCHAR( 50 ),
`size` VARCHAR( 50 ),
`mime` VARCHAR( 50 ),
`created` VARCHAR( 50 ),
`lastedit` VARCHAR( 50 ),
PRIMARY KEY ( `id` )
);

CREATE TABLE `history` (
`id` INT( 15 ) AUTO_INCREMENT ,
`filename` VARCHAR( 50 ),
`created` VARCHAR( 50 ),
`lastedit` VARCHAR( 50 ),
`action` VARCHAR( 50 ),
PRIMARY KEY ( `id` )
);


Each time you create a table, it is a separate query. Also note your administrator table does not have an index. Thus you have two choices, you can break each table creation into its own query:

<?php
mysql_error());
$tables1 = "CREATE TABLE `administrator` (
`uname` VARCHAR( 15 ),
`pword` VARCHAR( 15 ),
`email` VARCHAR( 25 ),
`lastlogin` VARCHAR( 25 )
);";

$tables2 = "CREATE TABLE `files` (
`id` INT( 15 ) AUTO_INCREMENT ,
`filename` VARCHAR( 50 ),
`size` VARCHAR( 50 ),
`mime` VARCHAR( 50 ),
`created` VARCHAR( 50 ),
`lastedit` VARCHAR( 50 ),
PRIMARY KEY ( `id` )
);";

$tables2 = "CREATE TABLE `history` (
`id` INT( 15 ) AUTO_INCREMENT ,
`filename` VARCHAR( 50 ),
`created` VARCHAR( 50 ),
`lastedit` VARCHAR( 50 ),
`action` VARCHAR( 50 ),
PRIMARY KEY ( `id` )
);";

$query = mysql_query($tables1);
$query = mysql_query($tables2);
$query = mysql_query($tables3);

?>


Or you can use PHP5's MySQL Improved [mysqli] extension, which might look like this:

$link = mysqli_connect("localhost", "uname", "pword");
mysqli_select_db($link, "test");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}


$tables ="CREATE TABLE `administrator` (
`uname` VARCHAR( 15 ),
`pword` VARCHAR( 15 ),
`email` VARCHAR( 25 ),
`lastlogin` VARCHAR( 25 )
);

CREATE TABLE `files` (
`id` INT( 15 ) AUTO_INCREMENT ,
`filename` VARCHAR( 50 ),
`size` VARCHAR( 50 ),
`mime` VARCHAR( 50 ),
`created` VARCHAR( 50 ),
`lastedit` VARCHAR( 50 ),
PRIMARY KEY ( `id` )
);

CREATE TABLE `history` (
`id` INT( 15 ) AUTO_INCREMENT ,
`filename` VARCHAR( 50 ),
`created` VARCHAR( 50 ),
`lastedit` VARCHAR( 50 ),
`action` VARCHAR( 50 ),
PRIMARY KEY ( `id` )
);";

mysqli_multi_query($link, $tables) or die(mysqli_error($link));

  • 0

#5 Guest_Jaan_*

Guest_Jaan_*
  • Guest

Posted 17 January 2008 - 06:48 AM

well i tried 'em all.. ;) didnt work..


<?php
mysql_error());
$tables1 = "CREATE TABLE `administrator` (
`uname` VARCHAR( 15 ),
`pword` VARCHAR( 15 ),
`email` VARCHAR( 25 ),
`lastlogin` VARCHAR( 25 )
);";

$tables2 = "CREATE TABLE `files` (
`id` INT( 15 ) AUTO_INCREMENT ,
`filename` VARCHAR( 50 ),
`size` VARCHAR( 50 ),
`mime` VARCHAR( 50 ),
`created` VARCHAR( 50 ),
`lastedit` VARCHAR( 50 ),
PRIMARY KEY ( `id` )
);";

$tables2 = "CREATE TABLE `history` (
`id` INT( 15 ) AUTO_INCREMENT ,
`filename` VARCHAR( 50 ),
`created` VARCHAR( 50 ),
`lastedit` VARCHAR( 50 ),
`action` VARCHAR( 50 ),
PRIMARY KEY ( `id` )
);";

$query = mysql_query($tables1);
$query = mysql_query($tables2);
$query = mysql_query($tables3);

?>

this one worked.. almost because i received this error:

Query was empty


dang.. wierd
  • 0

#6 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 17 January 2008 - 07:33 AM

...the second $table2 should be $table3...

Also note md5 hashes are 32 characters, your password field only allows 15 characters. Are you storing your passwords in plain text?
  • 0

#7 Guest_Jaan_*

Guest_Jaan_*
  • Guest

Posted 17 January 2008 - 09:42 AM

...the second $table2 should be $table3...

Also note md5 hashes are 32 characters, your password field only allows 15 characters. Are you storing your passwords in plain text?


this password thingy is just temporary ;)
  • 0





Also tagged with one or more of these keywords: syntax, syntax error

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download