I am not receiving any errors when trying to insert data in the database. But it at the same time there is nothing being entered.
I watched a video that has the same example. I tried a different statement for creating the Mysqli object and still do not work.
//This part of the code is in another php file
<?php
$data = array("name"=>"patrick", "age"=>"25");
$string = http_build_query($data);
$ch = curl_init("http://localhost//data.php");
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$string);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_exec($ch);
curl_close($ch);
?>
//This part of the code is in the data.php
<?php
if(isset($_POST['name'], $_POST['age']))
{
//$db = mysqli_connect("localhost","root","password","testPost");
$db = new Mysqli("localhost","root","password","testPost");
$name = $db->real_escape_string($_POST['name']);
$age = (int)$_POST['age'];
$query = "INSERT INTO data SET myData = '$name, $age'";
$db->query($query);
}
?>
I expect data to be inserted in a database. The database is called testPost and it has two columns called id and myData