0

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]);
        mysql_query($insert_sql);
    }

data1 is the array..

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

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by simplypixie
4

@christian.i.wibowo

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\\

0

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

 syntax error, unexpected '%' in
 or
 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..

0

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]);
 mysql_query($format_sql);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.