PDA

View Full Version : SQL synax problem


killa seven
04-06-2010, 10:55 PM
$vbulletin->db->query_write("CREATE TABLE IF NOT EXISTS ".TABLE_PREFIX."`dbh_victims` (
`id` INT( 4 ) NOT NULL AUTO_INCREMENT ,
`username` VARCHAR( 45 ) NOT NULL ,
`beat` VARCHAR( 45 ) NOT NULL ,
`cscore` INT( 1 ) NOT NULL DEFAULT '0' ,
`oscore` INT( 1 ) NOT NULL DEFAULT '0'
UNIQUE (
`id`
");

MySQL 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 '(
'id'' at line 7
Error Number : 1064


im thinking that theres an extra comma some where near id

Lynne
04-07-2010, 01:03 AM
look at your last three lines.... now tell me where the ending ") is for the first line.

killa seven
04-07-2010, 01:29 AM
what do you mean ending? i put an ending parentheses at the end of ") but still no go

Lynne
04-07-2010, 01:35 AM
Yeah, so where is the ending paren to the UNIQUE ( that you have?

killa seven
04-07-2010, 01:38 AM
oh ok

$vbulletin->db->query_write("CREATE TABLE IF NOT EXISTS ".TABLE_PREFIX."`dbhVictims` (
`id` INT( 4 ) NOT NULL AUTO_INCREMENT ,
`username` VARCHAR( 45 ) NOT NULL ,
`beat` VARCHAR( 45 ) NOT NULL ,
`cscore` INT( 1 ) NOT NULL DEFAULT '0' ,
`oscore` INT( 1 ) NOT NULL DEFAULT '0'
UNIQUE (`id`)
");

i put the paren after id no syntax errors but it isn't created in the database

TigerC10
04-07-2010, 02:27 AM
You're still missing a closing parenthesis (from right after the dbhVictims), and you may also want to get rid of the ` symbol. In Perl the `operator performs a system command and PHP is supposed to be Perl embedded in HTML (but I'm unclear as to the status of the ` operator in PHP).

Try this instead...


$vbulletin->db->query_write(
"CREATE TABLE IF NOT EXISTS ".TABLE_PREFIX."dbhVictims (
id INT( 4 ) NOT NULL AUTO_INCREMENT,
username VARCHAR( 45 ) NOT NULL,
beat VARCHAR( 45 ) NOT NULL,
cscore INT( 1 ) NOT NULL DEFAULT 0,
oscore INT( 1 ) NOT NULL DEFAULT 0,
PRIMARY KEY(id)
)"
);


Doing it this way (with the staggered indents) makes errors more obvious to see in the future.

killa seven
04-07-2010, 02:28 AM
yeagh i thought those tick marks looked weird...

edits..

its not going into the database for some reason

TigerC10
04-07-2010, 02:33 AM
There's nothing wrong with the backticks in a MySQL command. I know of many .SQL files that use them. Using the ` operator can be confusing in Perl though. It's not required, so why put them in?

killa seven
04-07-2010, 02:36 AM
yeagh... its still not going into the database tho

there is actually no syntax errors now its just not going in when i upload the product

TigerC10
04-07-2010, 02:46 AM
Well it might have to do with the IF NOT EXISTS that you gave it. If you ran this code with the wrong syntax then it may have created an empty table. Then when you ran it a second time the empty table was there and it didn't issue the create statement again.

Whatever method you're using to view your database, you may be missing the table. Sometimes viewers sort based on the capital letters and the lower case letters. If it's a web-based viewer then you may need to close it down and open it again (browser cache could mess you up).

killa seven
04-07-2010, 02:53 AM
its phpmyadmin

i also have workbench but in phpmyadmin right now

TigerC10
04-07-2010, 03:30 AM
Well, close down the tab or the browser and then bring it up again after a few minutes (just in case).

killa seven
04-07-2010, 06:55 AM
its just not going in.. closed it down and retried a couple times

Marco van Herwaarden
04-09-2010, 10:09 AM
Are you upgrading the product, or uninstalling/installing?

killa seven
04-09-2010, 12:37 PM
uninstalling/installing

building a poll system for a battle hack i am making

finally got it to work after hours of banging my head on the desk lol


heres the code i got away with... i feel stupid because i don't see the difference haha


$vbulletin->db->query_write("CREATE TABLE IF NOT EXISTS ".TABLE_PREFIX."`dbh_victims` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT ,
`username` VARCHAR( 50 ) NOT NULL ,
`beat` VARCHAR( 50 ) NOT NULL ,
`cscore` INT( 10 ) NOT NULL ,
`oscore` INT( 10 ) NOT NULL,
UNIQUE (`id`)
) ");