Note that there are some explanatory texts on larger screens.

plurals
  1. POInserting checkbox values into MySQL Database with PHP
    text
    copied!<p>everyone.</p> <p>I know this is a far treated subject, but I've looked everywhere and cannot get it solved.</p> <p>I have a series of checkboxes in my webpage and need to insert the values into a database.</p> <p>For what I've read, it's supposed to be done this way:</p> <pre><code>&lt;tr&gt; &lt;td class="titulofila"&gt;Sal&amp;oacute;n Completo con: &lt;/td&gt; &lt;td&gt; &lt;table width="100%"&gt;&lt;tr&gt;&lt;td&gt; &lt;label&gt; &lt;input name="equipSalon[]" type="checkbox" id="equipSalon[]" value="mesa" /&gt; mesas &lt;/label&gt; &lt;/td&gt;&lt;td&gt; &lt;label&gt; &lt;input name="equipSalon[]" type="checkbox" id="equipSalon[]" value="sillas" /&gt; sillas &lt;/label&gt; &lt;/td&gt;&lt;td&gt; &lt;label&gt; &lt;input name="equipSalon[]" type="checkbox" id="equipSalon[]" value="sofa" /&gt; sof&amp;aacute;&lt;/label&gt; &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; </code></pre> <p>And then, in the PHP script that the submit button takes to:</p> <pre><code> $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); </code></pre> <p>I have more than this checkboxes and this doesn't work, just says "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 21"</p> <p>If anyone wants to look at the full index.html and php files, you can have them here: <a href="http://paste.ideaslabs.com/show/8qEHDnsZdr" rel="nofollow">http://paste.ideaslabs.com/show/8qEHDnsZdr</a> the form starts at line 147. And the PHP File in here: <a href="http://paste.ideaslabs.com/show/IJFLSHM7Ka" rel="nofollow">http://paste.ideaslabs.com/show/IJFLSHM7Ka</a></p> <p>Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload