At the beginning, I learned how to insert multiple data records in the insert file of medoo in PHP: {code...}. How can I insert post data into the database? Can you give a simple DEMO? Thank you! The data from post is roughly as follows: {code ...} I tried it many times... at the beginning, I learned how to insert multiple data entries in the medoo file insert:
$last_user_id = $database->insert("account", [ [ "user_name" => "foo", "email" => "foo@bar.com", "age" => 25, "city" => "New York", "(JSON) lang" => ["en", "fr", "jp", "cn"] ], [ "user_name" => "bar", "email" => "bar@foo.com", "age" => 14, "city" => "Hong Kong", "(JSON) lang" => ["en", "jp", "cn"] ]]);
How can I insert post data to a database? Can you give a simple DEMO? Thank you!
The data from post is roughly as follows:
{ "name" : "xiaoming", "age" : 20},{ "name" : "lihong", "age" : 25}
I tried it many times but failed. I hope you can answer it. Thank you.
Reply content:
At the beginning, I learned how to insert multiple data entries in the medoo file insert:
$last_user_id = $database->insert("account", [ [ "user_name" => "foo", "email" => "foo@bar.com", "age" => 25, "city" => "New York", "(JSON) lang" => ["en", "fr", "jp", "cn"] ], [ "user_name" => "bar", "email" => "bar@foo.com", "age" => 14, "city" => "Hong Kong", "(JSON) lang" => ["en", "jp", "cn"] ]]);
How can I insert post data to a database? Can you give a simple DEMO? Thank you!
The data from post is roughly as follows:
{ "name" : "xiaoming", "age" : 20},{ "name" : "lihong", "age" : 25}
I tried it many times but failed. I hope you can answer it. Thank you.
If it is not form submission, that is, the content-type of the request header is not equal to application/x-www-form-urlencoded or multipart/form-data, PHP cannot automatically parse the data you passed and assign the value to $ _ POST. You need to usephp://input
Obtain all transmitted content and parse the data manually.
Assume that the data you sent is:
[ {"name": "xiaoming", "age": 20}, {"name": "lihong", "age": 25}]
So you can write:
$_POST = json_decode( file_get_contents('php://input'), true);$last_user_id = $database->insert("account", $_POST);
In addition to medoo, what other useful database tools does php provide?