Reputation: 11
I'm trying to save an array of values into a MySQL database. Here is my code:
$values = array('jaime','11124583363', '5554625', '312458795','1999-12-02','soldierjesus', 'calle 12', 'carismatica', 'necesito oracion', '1', '1');
$data->create_persons('new_person', $values);
public function create_persons($table, $values)
{
$query = ("INSERT INTO $table ('name', 'number_document','phone', 'cell_phone', 'birth_date', 'email',
'address', 'other_church', 'pray_request', 'districts_id', 'professions_id')
VALUES('".implode("','", $values).")'") or die(mysqli_error());
mysqli_query($this->_connection, $query);
}
The numbers are can't --> ''
How quit this?
Thanks
Upvotes: 0
Views: 213
Reputation: 144
Didn't give it much time, but I think the insert query is wrong here:
`$query = ("INSERT INTO $table ('name', 'number_document','phone', 'cell_phone', 'birth_date', 'email', 'address', 'other_church', 'pray_request', 'districts_id', 'professions_id') VALUES('".implode("','", $values)."')") or die(mysqli_error());`
The ' (single quote) to close the VALUES() was in the wrong place.
Regards, Charlie
Upvotes: 0
Reputation: 3776
change
VALUES('".implode("','", $values).")'")
into
VALUES('".implode("','", $values)."')")
in other words change the ")'"
into "')"
Upvotes: 4