2013-11-26 102 views
-1

幫助請。 我想插入數據庫Urunler []。但它沒有得到它的工作。php陣列和插入

<select name="urunler[1]"> <option selected="" value="DF-12">DF-12</option></select> 
<select name="urunler[2]"> <option selected="" value="DF-5">DF-5</option></select> 
<select name="urunler[3]"> <option selected="" value="DF-15">DF-15</option></select> 

$urunler = array(); 
$values = array(); 


foreach($_POST[$urunler] as $key => $urun_value) { 
    $values[] = "('" . mysql_real_escape_string($urun_value) . "')"; 
} 

$val_string = implode(',', $values); 

$ekle = mysql_query (
    "INSERT INTO siparis_onay (
    id,urunkodu,urunfiyat,uadet,ekurun) 
    VALUES ('$id','$urunkodu','$urunfiyat','$uadet','$val_string') 
    "); 
+1

而你得到什麼錯誤,或者是你看到了什麼意外的行爲? – Jasper

+0

我在數據庫中看不到任何價值 – unal

回答

0
<select name="urunler[]"> 
    <option value="DF-5">DF-5</option> 
    <option value="DF-12">DF-12</option> 
    <option value="DF-1">DF-1</option> 
</select> 

<?php 


foreach ($_POST['urunler'] as $key => $value) { 
    $values[] = "('" . mysql_real_escape_string($value) . "')"; 
} 

$val_string = implode(',', $values);