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

Recommended Answers

All 3 Replies

Member Avatar for LastMitch

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

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

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);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.