2
votes

// mysql table creation

CREATE TABLE `users` (
  `id` int NOT NULL,
  `name` varchar(45) NOT NULL,
  `gender` varchar(45) NOT NULL,
  `designation` varchar(45) NOT NULL,
  `address` varchar(45) NOT NULL,
  `email` varchar(45) NOT NULL,
  `password` varchar(45) NOT NULL,
  `cpassword` varchar(45) NOT NULL,
  `age` int NOT NULL,
  `phone` int NOT NULL,
  `pincode` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci

// Postman post request

  {
   "name":"krithi",
   "age":15,
   "gender":"female",
   "phone":1234567890,
   "designation":"volunteer",
   "address":"chennai",
   "pincode":90,
   "password":"ac",
   "cpassword":"ac",
   "email":"[email protected]"

}       

// output in postman

{"code":1010,"message":"Data integrity violation"}  

But it works well for get request. Any help would be much appreciated.

I changed my table into a simpler one   

CREATE TABLE d ( name varchar(45) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci and my json is` {

    "name" : "abc"
    }
*and the response is* 

    {
    "code": 9999,
    "message": "Argument 1 passed to Tqdev\\PhpCrudApi\\Database\\ColumnsBuilder::quoteColumnName() must be an instance of Tqdev\\PhpCrudApi\\Column\\Reflection\\ReflectedColumn, null given, called in C:\\Users\\vimy9\\OneDrive\\Desktop\\clone\\php-crud-api\\api.php on line 4892"
}
1
show the table definition (SHOW CREATE TABLE {tablename}), what code are you executing? What is the specific command being generated? Welcome to SO. Please provide mode details up front.danblack
You have to specify a primary key on the simpler table.Clutch Prince

1 Answers

3
votes

You have id int NOT NULL in your query but you're not passing an ID while inserting, if you want it to be auto generated, it should be id int NOT NULL AUTO_INCREMENT.