hi... i want to insert data from array using mysql from php..and now i using this code :

for ($i = 0; $i < count($data1); $i++) {                     
        $insert_sql = sprintf("INSERT INTO detail_paket (id_paket, menu_paket) select paket.id,'\"%s\"' from     paket where paket.nama_paket='$nama_paket'",%data1[$i]);

data1 is the array..

what is the correct syntax to use \"%s\ ?

Member Avatar


what is the correct syntax to use \"%s\ ?

I assume that the query works and this syntax is the issue?

Instead of this: \"%s\

Try to add another back-slash (\): \\"%s\\

no, my the query didnt work, this is the error :

 syntax error, unexpected '%' in
 syntax error, unexpected "" in

i already tried using :

\"%s\ and \"%s"\ and %s and '%s' and "%s" and \"%s\" but the query still give me error..

Try it like this

$insert_sql = "INSERT INTO detail_paket (id_paket, menu_paket) select paket.id, %s from paket where paket.nama_paket='$nama_paket'";
 $format_sql = sprintf($insert_sql, $data1[$i]);