My SQL insert statement is resulting in nothing being added to my table. I have similar statements to other tables that are working fine, so my connection and database setup seems to be working OK. It’s something specific to the INSERT that is going wrong. Anyone have any ideas?
MySQL table structure:
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 ;
Statements:
$mysqli = new mysqli(xxxxx, "rpnews", xxxxx, "rpnews"); if (mysqli_connect_errno()) { printf("Connect failed: %sn", 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')");
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Also Desc
is a reserved word,use backticks
Method 2
Wrong table name? gallery
!= gallery_new
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0