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

Re: insert values with \"%s\ error MYSQL PHP 80 80
Member Avatar

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

Re: insert values with \"%s\ error MYSQL PHP 80 80

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

Re: insert values with \"%s\ error MYSQL PHP 80 80

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 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.