Note that there are some explanatory texts on larger screens.

plurals
  1. POsimple check box insertion into database using mysqli php
    primarykey
    data
    text
    <p>I'm new to PHP. I learnt how to insert data from a textbox but I am facing a problem now when I have to get data from a checkbox. I checked out other posts but they are either too advanced and most of them are using mysql rather than mysqli.</p> <p>I have ->> two check boxes and a submit button</p> <p>I would like insert the value of the check box into the database, when selected(one or both).</p> <p>Thanks</p> <p>HTML FORM Code:</p> <p></p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Insert Data&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt; check box testing &lt;/h1&gt; &lt;form name="form1" method="post" action="checkbox_test.php" &gt; &lt;fieldset&gt; &lt;legend&gt; Checkbox Trial &lt;/legend&gt; &lt;h3&gt; Subject selection &lt;/h3&gt; &lt;input type="checkbox" name="PHP" value="php" id="cbsubp1"/&gt; PHP &lt;br/&gt; &lt;input type="checkbox" name="ASP" value="course[]" id="cbsub2"/&gt; ASP.NET &lt;br/&gt; &lt;input type="submit" value="submit" id="submit"/&gt; &lt;/fieldset&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>and PHP code is </p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Insert Data&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt; check box testing &lt;/h1&gt; &lt;?php $con=mysqli_connect("localhost","root","","chkbox"); //check connection if(mysqli_connect_errno()) { echo "Cannot connect to mySQL:".mysqli_connect_error(); } else { echo "Connected to mySQL succesfully"; } $query= "INSERT into sub(Subject1) VALUES('$_POST[php]')"; if (!mysqli_query($con,$query)) { die('Error: ' . mysqli_error($con)); } echo "record added"; ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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