Hy! I am new to PHP and and have following question: I have written a form where the user is able to select some columns of a database table. This selection is done using an array. Now I want to include this array into a SQL SELECT statement. I have tried the following- but without any positive result. In the manuals I use I can not really find an answer to that. $array = $_REQUEST['selection']; if ($c = @oci_connect("user","pw","xe")) { $s = oci_parse($c,"SELECT $array FROM resources "); oci_execute($s,OCI_DEFAULT); Code (markup): Thanks for help!
Try: "SELECT " . implode(', ', $array) ." FROM resources " PHP: You really should filter and validate the input before putting it in the query though.
Little less complex. Just implode the array before adding it to the query. $array = $_REQUEST['selection']; $array = implode(', ', $array); if ($c = @oci_connect("user","pw","xe")) { $s = oci_parse($c,"SELECT $array FROM resources "); oci_execute($s,OCI_DEFAULT); PHP: