views:

75

answers:

3

Do you have any idea why i get this:

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 '``, `title` varchar(255) collate latin1_general_ci NOT NULL default ``,' at line 3

The code is like this (the part im having problem with...)

$sql = 'CREATE TABLE `forum` (
                        `postid` bigint(20) NOT NULL auto_increment,
                        `author` varchar(255) collate latin1_general_ci NOT NULL default ``,
                        `title` varchar(255) collate latin1_general_ci NOT NULL default ``,
                        `post` mediumtext collate latin1_general_ci NOT NULL,
                        `showtime` varchar(255) collate latin1_general_ci NOT NULL default ``,
                        `realtime` bigint(20) NOT NULL default `0`,
                        `lastposter` varchar(255) collate latin1_general_ci NOT NULL default ``,
                        `numreplies` bigint(20) NOT NULL default `0`,
                        `parentid` bigint(20) NOT NULL default `0`,
                        `lastrepliedto` bigint(20) NOT NULL default `0`,
                        `author_avatar` varchar(30) collate latin1_general_ci NOT NULL default `default`,
                        `type` varchar(2) collate latin1_general_ci NOT NULL default `1`,
                        `stick` varchar(6) collate latin1_general_ci NOT NULL default `0`,
                        `numtopics` bigint(20) NOT NULL default `0`,
                        `cat` bigint(20) NOT NULL,
                        PRIMARY KEY  (`postid`)
                        );';
                mysql_query($sql,$con) or die(mysql_error());

Help would be greatly appreciated!

+3  A: 

You are using backticks instead of quotes for strings. Change this:

default ``

to this:

default ''

The full statement should be:

CREATE TABLE `forum` (
                    `postid` bigint(20) NOT NULL auto_increment,
                    `author` varchar(255) collate latin1_general_ci NOT NULL default '',
                    `title` varchar(255) collate latin1_general_ci NOT NULL default '',
                    `post` mediumtext collate latin1_general_ci NOT NULL,
                    `showtime` varchar(255) collate latin1_general_ci NOT NULL default '',
                    `realtime` bigint(20) NOT NULL default '0',
                    `lastposter` varchar(255) collate latin1_general_ci NOT NULL default '',
                    `numreplies` bigint(20) NOT NULL default '0',
                    `parentid` bigint(20) NOT NULL default '0',
                    `lastrepliedto` bigint(20) NOT NULL default '0',
                    `author_avatar` varchar(30) collate latin1_general_ci NOT NULL default 'default',
                    `type` varchar(2) collate latin1_general_ci NOT NULL default '1',
                    `stick` varchar(6) collate latin1_general_ci NOT NULL default '0',
                    `numtopics` bigint(20) NOT NULL default '0',
                    `cat` bigint(20) NOT NULL,
                    PRIMARY KEY  (`postid`)
                    );
Mark Byers
And as Tibo pointed out, this query needs to be in double quotes, not single quotes.
Mark Byers
+5  A: 
`author` varchar(255) collate latin1_general_ci NOT NULL default ``,

'author' is a column name, hence why it goes it backticks. But the default '' is a value so it should be in quotation marks, not backticks, methinks.

If this is the case, same goes for all other defaults.

LeguRi
ok, thanks, i'll try it now, hold on a sec.
Tibo
A: 

Thanks for responses. I had actually done this before (putting ' instead of ` ), but it just showed me a blank page....

I figured out my problem. I either had to put backslash before each ' or just change the

$sql = 'CREATE TABLE `forum` (

to

$sql = "CREATE TABLE `forum` (

(note the quotes)

Thanks anyway, it helped me figure it out!

Tibo
Tibo: look up the HEREDOC syntax, it'll let you assign large blobs of text like that without having to worry about escaping quotes: http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
Marc B