I am having error trying to store data into a database. I need help on how best to fix this my code, so that my array content can be stored in a my database. When I tried to echo the content, it worked not to store the data in my database is the problem. Here is my code:
foreach ($data['players'] as $myp) {
// echo $myp["name"]."<br>";
$name = $myp['name'];
$posi = $myp['position'];
$nation = $myp['nationality'];
$market = $myp['marketValue'];
}
//insert into mysql table
mysql_select_db($db, $conn); //database and connection
$date = date('Y-m-d H:m:s'); //date stamp formatting
//sql query that insert the user info into the database
$sql = "INSERT INTO staffdb ( Name, Position, Nationality, Market, Created)
VALUES($name, $posi, $nation, $market, $date)";
echo $name . "<br>";
//if the connection is sucessful, display regards message
if (mysql_query($sql, $conn)) {
echo "Thank you <br/>";
} else { //if the connection is not established
die('Error: ' . mysql_error());
}
Here is the error I was getting: Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Costa, Centre Forward, Spain, 45,000,000 €, 2017-03-31 23:03:04)' at line 2
In the error it printed the right value which i would like to be instead stored in the database.
Kindly correct my SQL part so that I can get my foreach data into my database.
Thanks alot!