I'm running into an issue with a mysqli prepared statement. It's probably some rookie mistake; I'm not too familiar with things like this. Any help is appreciated.
I have two arrays, $alpha[]
and $bravo[]
. Both have 20 pairings, but to simplify:
$alpha = array('name', 'age', 'color');
$bravo = array(
'name' => 'John Doe',
'age' => 22,
'color' => 'blue',
);
I want to insert the data from $bravo[]
into my table by defining the column headers with $alpha[]
and then binding the data from $bravo[]
to the query, and then executing the query. Here's an example of what I want to do:
$columns = implode(',', $alpha);
$query_values = '?,?,?';
$query = "INSERT INTO table ($columns) VALUES ($query_values)";
$type = 'sis';
$real_values = implode(',', $bravo);
if($stmt = $mysqli->prepare($query)){
$stmt->bind_param($type, $real_values);
if($stmt->execute()){
// success
}
}
This is not working for me - any help or insight you guys can offer (including other ways to accomplish what I want to do) is much appreciated.