everyone。使用PHP將複選框值插入MySQL數據庫
我知道這是一個治療得很好的科目,但我到處尋找,無法解決。
我在我的網頁中有一系列複選框,需要將值插入到數據庫中。
對於我讀過,它應該做這樣:
<tr>
<td class="titulofila">Salón Completo con: </td>
<td>
<table width="100%"><tr><td>
<label>
<input name="equipSalon[]" type="checkbox" id="equipSalon[]" value="mesa" />
mesas </label>
</td><td>
<label>
<input name="equipSalon[]" type="checkbox" id="equipSalon[]" value="sillas" />
sillas </label>
</td><td>
<label>
<input name="equipSalon[]" type="checkbox" id="equipSalon[]" value="sofa" />
sofá</label>
</td></tr></table>
</td>
</tr>
,然後在PHP腳本,提交按鈕花費:
$equipSalonF=mysql_real_escape_string(implode(',', $_POST['equipSalon']));
mysql_query("INSERT INTO markers (ciudad,
zona,address,name,
telefono,email,piso,
tipo,erasmus,nhabitaciones,
plazas,equipHabita,nbanos,
salon,cocina,electrodomesticos,
garaje,internet,calefaccion,
sexo,precio,superficie,otros,
fecha,lat,lng)
VALUES ('{$_POST['ciudad']}','{$_POST['zona']}',
'{$_POST['address']}','{$_POST['name']}','{$_POST['telefono']}',
'{$_POST['email']}','{$_POST['piso']}','{$_POST['tipo']}',
'{$_POST['erasmus']}','{$_POST['nhabitaciones']}',
'{$_POST['plazas']}','{$equipHabitaF}',
'{$_POST['nbanos']}','{$equipSalonF}',
'{$equipCocinaF}','{$equipElectroF}','{$_POST['garaje']}',
'{$_POST['internet']}','{$_POST['calefaccion']}',
'{$_POST['sexo']}','{$_POST['precio']}',
'{$_POST['superficie']}','{$_POST['otrosF']}',
'{$_POST['fecha']}','{$_POST['lat']}',
'{$_POST['lng']}'",$link);
我有更多的比這複選框,這不工作,只是說:「你的SQL語法錯誤;檢查對應於您的MySQL服務器版本的手冊,以便在第21行使用正確的語法」
如果有人想看看完整的index.html和php文件,你可以在這裏找到它們:http://paste.ideaslabs.com/show/8qEHDnsZdr表格從147行開始。而PHP文件在這裏:http://paste.ideaslabs.com/show/IJFLSHM7Ka
在此先感謝。
除了你應該刪除ID屬性。您只需要爲name屬性執行此操作。 – animuson 2012-02-04 17:36:21
如果你真的想看看底下發生了什麼,轉儲POST變量:<?php echo「<! - POST:」;的print_r($ _ POST);回聲「 - > \ n」; ?> ...然後使用視圖源來查看註釋中的調試 – dar7yl 2012-02-04 23:04:38