Note that there are some explanatory texts on larger screens.

plurals
  1. PORegistration Form - Checkbox Is Inserted on new rows in Database
    primarykey
    data
    text
    <p>I'm Practising PHP programming. I have made a Registration Form which has</p> <p>2 Text Area (For First Name and Last) 2 Radio Buttons (For Gender Selection - Haven't started work on that yet) 8 Check boxes (4 each for Subject and Hobbies)</p> <p>I have a Database Table by the name of persons which has </p> <p>5 Columns (FirstName,LastName,Gender,Subject,Hobbies)</p> <p>The Data from the form is being fetched, but each check box is inserted in the next row below the name. </p> <p>For example David Bekham the subject php asp and hobby tv reading instead of appearing on the same row and against the name of the record, they appear on the next row.</p> <p>As this is my first time, my question is</p> <p>Q1 :- Is that how a record for such a form supposed to appear? Q2 :- If not then where/what is the problem? Q3 :- Could you either help me radio button code or provide me an easy link to learn it.</p> <p><strong>HTML FORM</strong></p> <pre><code>&lt;!DOCTYPE&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Insert Data&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt; Insert to Register &lt;/h1&gt; &lt;form name="form1" method="post" action="insert.php" &gt; &lt;fieldset&gt; &lt;legend&gt; Registration Form &lt;/legend&gt; FirstName &lt;input type="text" name="a" value="Enter firstname"/&gt; &lt;br/&gt;&lt;br/&gt; LastName &lt;input type="text" name="b" value="Enter lastname"/&gt; &lt;br/&gt;&lt;br/&gt; &lt;h3&gt; Gender selection &lt;/h3&gt; Male &lt;input type="radio" name="gender"/&gt; female &lt;input type="radio" name="gender"/&gt; &lt;br/&gt;&lt;br/&gt; &lt;h3&gt; Subject selection &lt;/h3&gt; &lt;input type="checkbox" name="sb[]" value="php"/&gt; PHP &lt;br/&gt; &lt;input type="checkbox" name="sb[]" value="asp"/&gt; ASP.NET &lt;br/&gt; &lt;input type="checkbox" name="sb[]" value="html"/&gt; HTML &lt;br/&gt; &lt;input type="checkbox" name="sb[]" value="css"/&gt; CSS &lt;br/&gt;&lt;br/&gt; &lt;h3&gt; Hobbies selection &lt;/h3&gt; &lt;input type="checkbox" name="hb[]" value="tv"/&gt; Tv &lt;br/&gt; &lt;input type="checkbox" name="hb[]" value="pc"/&gt; Computer &lt;br/&gt; &lt;input type="checkbox" name="hb[]" value="book"/&gt; Reading books &lt;br/&gt; &lt;input type="checkbox" name="hb[]" value="games"/&gt; Games &lt;br/&gt;&lt;br/&gt; &lt;input type="submit" name="submit" value="Submit"/&gt; &lt;/fieldset&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>php file</strong></p> <pre><code>&lt;!DOCTYPE&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Processing_Insert_main&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;?php // =============== code for Connection_SQLi ============================== $con=mysqli_connect("localhost","root","","Ismat_db"); //check connection if(mysqli_connect_errno()) { echo "Cannot connect to mysqli:" . mysqli_connect_error(); } // =============== code for Submit_input type ================================ if(isset($_POST['submit'])) { // ========== code for Name_TextArea =============== $sqlta = "INSERT INTO persons(FirstName,LastName)VALUES ('$_POST[a]','$_POST[b]')"; if (!mysqli_query($con,$sqlta)) { die('Error: ' . mysqli_error($con)); } echo "record added for name&lt;br/&gt;"; // ====== code for subject_checkbox ================ $s = $_POST['sb']; $how_many=count($s); for($i=0;$i&lt;$how_many;$i++) { echo "You Selected: " .$s[$i]."&lt;br/&gt;"; if(!mysqli_query($con,"INSERT INTO persons(Subject) VALUES('$s[$i]')")) { echo "Not Recorded".mysqli_error($con); } echo "Record Added for subject&lt;br/&gt;"; } // ============ Code for Hobbies_checkbox ======================== $h = $_POST['hb']; $how_many=count($h); for($i=0;$i&lt;$how_many;$i++) { echo "You Selected: " .$h[$i]."&lt;br/&gt;"; if(!mysqli_query($con,"INSERT INTO persons(Hobbies) VALUES('$h[$i]')")) { echo "Not Recorded".mysqli_error($con); } echo "Record Added for Hobby&lt;br/&gt;"; } //============================================================ echo '&lt;br/&gt;'.'&lt;a href="insert_main.html"&gt;'. "Back" . '&lt;/a&gt;'; } ?&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