I'm trying to insert several values into a database.
First I add these values to array (function/other code omitted):
$name = (isset($_POST['name']) ? ($_POST['name']) : "name");
$email = (isset($_POST['email']) ? ($_POST['email']) : "email");
$username = $mysqli->real_escape_string($_POST['username']);
$password = $mysqli->real_escape_string(md5($_POST['password']));
Like so:
$formvars = array();
array_push($formvars, $name, $email, $username, $password);
Then call function to insert:
$sql = array();
for ($i = 0; $i < count($formvars);$i++) {
$sql[] = $formvars[$i];
}
print_r(implode(',', $sql));
$qry = 'INSERT INTO chinesegame (name, email, username, password) VALUES '. implode(',' , $sql);
if(!$mysqli->query($qry))
{
echo "Error inserting data to the table
query:$qry";
return false;
}
return true;
My DB structure is as such:
It's giving me an insert error:
Error inserting data to the table query:INSERT INTO chinesegame (name, email, username, password) Dan,dthusky@gmail.com,danman,827ccb0eea8a706c4c34a16891f84e7b
Can I not build an insert string like that?