mysql中的保留名称

时间:2013-11-26 20:10:48

标签: php mysql

我的SQL插入语句导致我的表中没有添加任何内容。我有其他表工作正常的类似语句,所以我的连接和数据库设置似乎工作正常。这是INSERT特有的错误。有人有什么想法吗?

MySQL表结构:

CREATE TABLE `gallery_new` (
  `GalleryID` INTEGER(11) NOT NULL,
  `Status` MEDIUMTEXT COLLATE utf8_general_ci,
  `Title` MEDIUMTEXT COLLATE utf8_general_ci,
  `Desc` LONGTEXT COLLATE utf8_general_ci,
  `Author` MEDIUMTEXT COLLATE utf8_general_ci,
  `MCName` MEDIUMTEXT COLLATE utf8_general_ci,
  `Role` MEDIUMTEXT COLLATE utf8_general_ci,
  `ImageURL` MEDIUMTEXT COLLATE utf8_general_ci,
  `ThumbURL` MEDIUMTEXT COLLATE utf8_general_ci,
  `Timestamp` TIMESTAMP NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `Date` TEXT COLLATE utf8_general_ci,
  `PHPDate` MEDIUMTEXT COLLATE utf8_general_ci
)ENGINE=MyISAM
AUTO_INCREMENT=1 CHARACTER SET 'utf8' COLLATE 'utf8_general_ci'
COMMENT='';
ALTER TABLE `gallery_new` ADD PRIMARY KEY USING BTREE (`GalleryID`);

ALTER TABLE `gallery_new` ADD UNIQUE INDEX `GalleryID_new` USING BTREE (`GalleryID`);

ALTER TABLE `gallery_new` MODIFY COLUMN `GalleryID` INTEGER(11) NOT NULL AUTO_INCREMENT ;

说明:

$mysqli = new mysqli(xxxxx, "rpnews", xxxxx, "rpnews");
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

// GATHER INFO FOR THE DB INSERT
 $date = date("F j, Y"); 
 $phpdate = time();
 $author = ucfirst($user->data['username_clean']);
 $mcname = $user->profile_fields['pf_minecraftname'];
 $title = $mysqli->real_escape_string($_POST['posttitle']); 
  $body = $mysqli->real_escape_string($_POST['postbody']); 
if ($user->data['group_id'] == 4) { $role = 'Mod';}
elseif ($user->data['group_id'] == 5) { $role = 'Admin';}
else { $role = 'None';}

$mysqli->query("INSERT INTO gallery (Status, Title, Desc, Author, MCName, Role, ImageURL, ThumbURL, Date, PHPDate)
VALUES ('Live', '$title', '$body', '$author', '$mcname', '$role', '$path', '$paththumb', '$date', '$phpdate')");

2 个答案:

答案 0 :(得分:5)

错误的表名? gallery!= gallery_new

答案 1 :(得分:5)

此外Desc是保留字,请使用反引号

Docs