Why is is giving me an SQL syntax error?
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`)
)开发者_如何学Go;';
mysql_query($sql,$con) or die(mysql_error());
Help would be greatly appreciated!
`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.
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`)
);
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!
精彩评论