Note that there are some explanatory texts on larger screens.

plurals
  1. POThe word "Array" keeps appearing in my database
    primarykey
    data
    text
    <p>I keep getting the word "Array" in my database. I have checkboxes in my form and am having a hard time with it. I've tried different things, and this is the latest coding I have. What am I doing wrong? </p> <p>In my form, the checkboxes have the name "cats[]".</p> <p>I don't know if the first part matters (I saw that online and tried using it with the rest just in case)</p> <pre><code>if(count($cats) &gt; 0) { $str = implode(",", $cats); } </code></pre> <p>And then the actual code</p> <pre><code>$cats = array(); // Not good? //if(isset($_POST['submit'])) if($_SERVER['REQUEST_METHOD'] == 'POST') { if(isset($_POST['cats'])) { $cats = $_POST['cats']; } $categories= $_POST['categories']; // This saves it aa a string, as you can only save those values as string. $str = $categories . ": " . implode(", ", $cats); var_dump ($str); } </code></pre> <p>And this for the database</p> <pre><code>$sql="INSERT INTO form_corpo_test (compagnie) VALUES ('$_POST[cats]')"; </code></pre> <p><strong>EDIT:</strong></p> <p>This is the correct code (thank you guys for the help! I wish I could have marked two of your answers as the "best answer"). Hopefully this helped others (err, although they'll need to look into sql injections too of course).</p> <pre><code>$cats = array(); if($_SERVER['REQUEST_METHOD'] == 'POST') { if(isset($_POST['cats'])) { $cats = implode(",", $_POST['cats'] ); } $categories= $_POST['categories']; $str = $categories . ": " . $cats; } </code></pre> <p>And</p> <pre><code> $sql="INSERT INTO form_corpo_test (categories) VALUES ('$str')"; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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