GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 08-Jul-2003, 21:27
DropZite
 
Posts: n/a

MySQL Syntax Error


I got this error message when I was about to create a table in the database:

MySQL said:

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 '" . QUIZ_TABLE . " (
quiz_id mediumint(8) unsigned DEFAULT


Here's the whole code I used to create a new table... Maybe some of you here knows how to make it work? My version of MySql is 4.


Quote:
CREATE TABLE " . QUIZ_TABLE . " (
quiz_id mediumint(8) unsigned DEFAULT '0' NOT NULL auto_increment,
question text NOT NULL,
answer varchar(100) NOT NULL,
answer2 varchar(100) NOT NULL,
answer3 varchar(100) NOT NULL,
answer4 varchar(100) NOT NULL,
quiz_points tinyint(2) DEFAULT '1' NOT NULL,
quiz_type tinyint(1) DEFAULT '0' NOT NULL,
quiz_status tinyint(1) DEFAULT '0' NOT NULL,
quiz_from_user_id mediumint(8) DEFAULT '0' NOT NULL,
quiz_topic_id mediumint(8) unsigned DEFAULT '0' NOT NULL,
quiz_bot_post_id mediumint(8) unsigned DEFAULT '0' NOT NULL,
answered_by_user_id mediumint(8) DEFAULT '0' NOT NULL,
PRIMARY KEY (quiz_id),
KEY quiz_status (quiz_status),
KEY quiz_topic_id (quiz_topic_id),
KEY user_id (quiz_from_user_id)
);
CREATE TABLE " . QUIZ_CONFIG_TABLE . " (
config_name varchar(255) NOT NULL,
config_value text NOT NULL,
PRIMARY KEY (config_name)
);
INSERT INTO " . QUIZ_CONFIG_TABLE . " VALUES ('quizbot_id', '2'),
('forum_id', '1'),
('next_quiz', '" . ( time() - 3600 ) . "'),
('next_quiz_step', '1'),
('next_quiz_step_mode', '1'),
('disable', '1'),
('subject', 'Quiz Frage #{NUM} ...'),
('message', 'Und hier die neue Quiz-Frage:\r\n{QUIZ}'),
('subject2', 'Quiz beantwortet'),
('message2', 'Die Quiz-Frage wurde von {USERNAME} richtig beantwortet.\r\nDas Quiz wurde beendet.'),
('subject3', 'Fehler'),
('message3', 'Aus technischen Gründen wurde die Antwort von {USERNAME} irrtümlich als richtig markiert. Wir bitten dies zu entschuldigen.\r\nDas Quiz wird nicht wiedereröffnet und bleibt beendet. \r\n'),
('next_quiz_number', '1'),
('quiz_points_disable', '0'),
('banned_users', ''),
('banned_groups', ''),
('admin_user_id', '2'),
('allow_admin_in_quiz', '0'),
('allow_mod_in_quiz', '0'),
('allow_quiz_from_user_in_quiz', '0'),
('html', '1'),
('bbcode', '1'),
('smilies', '1'),
('imported_files', ''),
('last_start_time', '0'),
('version', '0.1.0');
ALTER TABLE " . USERS_TABLE . " ADD quiz_points MEDIUMINT(8) UNSIGNED DEFAULT '0' NOT NULL;
ALTER TABLE " . TOPICS_TABLE . " ADD topic_quiz MEDIUMINT(8) DEFAULT '0' NOT NULL;
ALTER TABLE " . POSTS_TEXT_TABLE . " ADD quiz_answer VARCHAR(100) NOT NULL;
";

anyone help!
  #2  
Old 09-Jul-2003, 00:33
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
I am confused; is this part of a SQL batch file or PHP script?
  #3  
Old 09-Jul-2003, 01:09
DropZite
 
Posts: n/a
Sorry for the confusion...

Yes this is part of a PHP script, and this part that I have taken is essential to be done.

I dont know how to convert this to MySQL syntax but from what I see they dont have much difference... Any helping hand here?


Thanks!
  #4  
Old 09-Jul-2003, 04:00
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough

Running MySQL statements together through an array


Looks like an install / upgrade script... anyway, here's what I would have done:

I would 'build' those different SQL queries into an array, then run them off the array using a foreach() loop; like this:
PHP Code:

<?php

// one query....
$sqls[] = 'CREATE TABLE ' . QUIZ_TABLE . '(
quiz_id mediumint(8) unsigned DEFAULT 0 NOT NULL auto_increment,
question text NOT NULL,
answer varchar(100) NOT NULL,
answer2 varchar(100) NOT NULL,
answer3 varchar(100) NOT NULL,
answer4 varchar(100) NOT NULL,
quiz_points tinyint(2) DEFAULT 1 NOT NULL,
quiz_type tinyint(1) DEFAULT 0 NOT NULL,
quiz_status tinyint(1) DEFAULT 0 NOT NULL,
quiz_from_user_id mediumint(8) DEFAULT 0 NOT NULL,
quiz_topic_id mediumint(8) unsigned DEFAULT 0 NOT NULL,
quiz_bot_post_id mediumint(8) unsigned DEFAULT 0 NOT NULL,
answered_by_user_id mediumint(8) DEFAULT 0 NOT NULL,
PRIMARY KEY (quiz_id),
KEY quiz_status (quiz_status),
KEY quiz_topic_id (quiz_topic_id),
KEY user_id (quiz_from_user_id)
) TYPE=MyISAM';
// another query...
$sqls[] = 'CREATE TABLE ' . QUIZ_CONFIG_TABLE . '(
config_name varchar(255) NOT NULL,
config_value text NOT NULL,
PRIMARY KEY (config_name)
) TYPE=MyISAM';
// keep on adding SQL statements hereon...

// then, finally, we run these queries
foreach( $sqls as $sql )
{
  mysql_query( $sql, $conn );
  // include any 'error checking' if needed, here...
}

?>

 
 

Recent GIDBlogToyota - 2008 September Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
phpMyAdmin error austinstace MySQL / PHP Forum 8 24-Aug-2007 20:42
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in ukrspp21 MySQL / PHP Forum 31 04-Jul-2006 21:41
Including Maps and strings?? maddie C++ Forum 17 05-Jul-2004 06:25
[script] E-mail webmaster error page BobbyDouglas PHP Code Library 0 19-Aug-2003 20:10
Windows: From only £20p/y,Linux: from $10p/m. ASP, ASP.NET, PHP, Free MySQL, +More EyotaHosts Web Hosting Advertisements & Offers 0 28-Jun-2003 13:54

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:14.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.