0

Following is my table structure:

CREATE TABLE `order` (
    `ID` BIGINT(20) NOT NULL AUTO_INCREMENT,
    `RenterRole_ID` INT(11) NULL DEFAULT NULL,
    `CreationTime` DATETIME NULL DEFAULT NULL,
    `BeginRentingDate` DATETIME NULL DEFAULT NULL,
    `EndRentingDate` DATETIME NULL DEFAULT NULL,
    `TripStartDate` DATETIME NULL DEFAULT NULL,
    `TripEndDate` DATETIME NULL DEFAULT NULL,
    `DeliveryDetails` VARCHAR(255) NULL DEFAULT NULL,
    `ReturningDetails` VARCHAR(255) NULL DEFAULT NULL,
    `SpareSpotBatteries` INT(11) NULL DEFAULT NULL,
    `spareInReach15Batteries` INT(11) NULL DEFAULT NULL,
    `Remarks` TEXT NULL,
    `OrdersCenter_ID` INT(11) NOT NULL DEFAULT '100',
    `HashedCCNumber` VARCHAR(255) NULL DEFAULT NULL,
    `CCExpiration` DATETIME NULL DEFAULT NULL,
    `CCHolderName` VARCHAR(255) NULL DEFAULT NULL,
    `CreatingController` VARCHAR(255) NULL DEFAULT NULL,
    `Debug` BIT(1) NOT NULL DEFAULT b'0',
    `TravelInsuranceOffer` BIT(1) NULL DEFAULT b'0',
    `DeviceInsurance` BIT(1) NULL DEFAULT b'0',
    `OrdersCenterRemarks` TEXT NULL,
    `Rivhit` VARCHAR(100) NULL DEFAULT NULL,
    `Invoice` VARCHAR(100) NULL DEFAULT NULL,
    `Payment` VARCHAR(200) NULL DEFAULT NULL,
    PRIMARY KEY (`ID`),
    INDEX `FK_OrderOrdersCenter_idx` (`OrdersCenter_ID`),
    INDEX `FK_OrderRenterRole_idx` (`RenterRole_ID`),
    CONSTRAINT `FK_OrderOrdersCenter` FOREIGN KEY (`OrdersCenter_ID`) REFERENCES `orderscenter` (`ID`),
    CONSTRAINT `FK_OrderRenterRole` FOREIGN KEY (`RenterRole_ID`) REFERENCES `renter_role` (`ID`)
)

when i try to INSERT data by following code:

$query = "INSERT INTO order (RenterRole_ID) VALUES (?)";
$stmt = $mysqli->prepare($query);
if (false === $stmt) {
    echo 'prepare() failed: ' . htmlspecialchars($mysqli->error);
    die();
}
$stmt->bind_param('i',$newRenterId);    
if (false === $bind) {
    echo 'bind_param() failed: ' . htmlspecialchars($stmt->error);
    die();
}
$stmt->execute();
$newOrderId = $stmt->insert_id;
$stmt->close(); 

cause following error:

prepare() failed: 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 'order (RenterRole_ID) VALUES (?)' at line 1

in other table INSERT code is working good only order table having issues.

chris85
  • 23,846
  • 7
  • 34
  • 51
Sandy
  • 83
  • 3
  • 11
  • 6
    `order` is reserved, use backticks or change table name. Compare how you used `order` in the `create` vs the `insert`. – chris85 Mar 22 '17 at 09:21
  • 5
    Possible duplicate of [Syntax error due to using a reserved word as a table or column name in MySQL](http://stackoverflow.com/questions/23446377/syntax-error-due-to-using-a-reserved-word-as-a-table-or-column-name-in-mysql) – chris85 Mar 22 '17 at 09:22
  • thanks, such a silly mistake – Sandy Mar 22 '17 at 09:22
  • 1
    Change your table name, it will work – Richardson. M Mar 22 '17 at 09:23

0 Answers0