Link to home
Start Free TrialLog in
Avatar of Wayeel Cade
Wayeel Cade

asked on

insert multiple radio button values to sql database

Hi there,

i want to build html form based attendance system which stores the data in mysql database after it's being submitted.
my problem is am using multiple radio button values for the teacher to choose  if the student is present or absent and then stores it to the database,
so it only selects the last option and deselects the previous ones? also how can i store the data via POST?
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

I am not clear on what your problem is

Radio buttons work as a select one only - is your problem that you can only select one or that you want only one option to be selected but you can select multiple?

If you want to select more than one - use a checkbox

If you want a single select and it is not working - then make sure your radio buttons have the same name

Will work as a select one only
<input type="radio" name="attendance" value="present"> Present
<input type="radio" name="attendance" value="absent"> Absent

Open in new window


Will NOT work as a select one only
<input type="radio" name="present" value="present"> Present
<input type="radio" name="absent" value="absent"> Absent

Open in new window


To store the data in a database you need a scripting language to intercept the post and do the DB store. What server side scripting technology are you planning to use?
Avatar of Wayeel Cade
Wayeel Cade

ASKER

Hi jullian sorry for the late reply.

to make it clear for the radio button there's seven days in the week so i want to choose present or absent for the days.
 
i want to use php for the scripting language.
this is my html file.

<table class="one">
    <th>Student Name</th>
    <th>Passport Number</th> 
    <th>VISA</th>
	<th>Class</th>
    <th>Country</th> 
    <th><P>M<br>
	       02</p></th>
		   <th><P>T<br>
	       03</p></th>
		   <th><P>W<br>
	       04</p></th>
		   <th><P>T<br>
	       05</p></th>
		   <th><P>F<br>
	       06</p></th>
		   
		   <th><P>M<br>
	       09</p></th>
		   <th><P>T<br>
	       10</p></th>
		   <th><P>W<br>
	       11</p></th>
		   <th><P>T<br>
	       12</p></th>
		   <th><P>F<br>
	       13</p></th>
		   
		   <th><P>M<br>
	       16</p></th>
		   <th><P>T<br>
	       17</p></th>
		   <th><P>W<br>
	       18</p></th>
		   <th><P>T<br>
	       19</p></th>
		   <th><P>F<br>
	       20</p></th>
	
	<th><P>M<br>
	       23</p></th>
		   <th><P>T<br>
	       24</p></th>
		   <th><P>W<br>
	       25</p></th>
		   <th><P>T<br>
	       26</p></th>
		   <th><P>F<br>
	       27</p></th>
	
  </tr>
  <td>ANWAR ALMBOK HUSIEN AYOUB</td>
    <td>H1G963P</td>
    <td>N.V</td>
	<td>INT</td>
    <td>LIB</td>
    <td>APR 18-JUN 18</td> 
     <fieldset id="group1">               
 <td><input type="radio" name="group1" value="present[0]">P</input>
     <input type="radio" name="group1" value="Absent[0]">A</input>
	 </fieldset>
	 
	 
	 <fieldset id="group2">               
 <td><input type="radio" name="group2" value="present[1]">P</input>
     <input type="radio" name="group2" value="Absent[1]">A</input>
	 </fieldset>
	 <fieldset id="group3">               
 <td><input type="radio" name="group3" value="present[2]">P</input>
     <input type="radio" name="group3" value="Absent[2]">A</input>
	 </fieldset>
	  <fieldset id="group4">               
 <td><input type="radio" name="group4" value="present[3]">P</input>
     <input type="radio" name="group4" value="Absent[3]">A</input>
	 </fieldset>
	  <fieldset id="group5">               
 <td><input type="radio" name="group5" value="present[4]">P</input>
     <input type="radio" name="group5" value="Absent[4]">A</input>
	 </fieldset>
	  <fieldset id="group6">               
 <td><input type="radio" name="group6" value="present[5]">P</input>
     <input type="radio" name="group6" value="Absent[5]">A</input>
	 </fieldset>
	  <fieldset id="group7">               
 <td><input type="radio" name="group7" value="present[6]">P</input>
     <input type="radio" name="group7" value="Absent[6]">A</input>
	 </fieldset>
	  <fieldset id="group8">               
 <td><input type="radio" name="group8" value="present[7]">P</input>
     <input type="radio" name="group8" value="Absent[7]">A</input>
	 </fieldset>
	  <fieldset id="group9">               
 <td><input type="radio" name="group9" value="present[8]">P</input>
     <input type="radio" name="group9" value="Absent[8]">A</input>
	 </fieldset>
	  <fieldset id="group10">               
 <td><input type="radio" name="group10" value="present[9]">P</input>
     <input type="radio" name="group10" value="Absent[9]">A</input>
	 </fieldset>
	  <fieldset id="group11">               
 <td><input type="radio" name="group11" value="present[10]">P</input>
     <input type="radio" name="group11" value="Absent[10]">A</input>
	 </fieldset>
	  <fieldset id="group12">               
 <td><input type="radio" name="group12" value="present[11]">P</input>
     <input type="radio" name="group12" value="Absent[11]">A</input>
	 </fieldset>
	  <fieldset id="group13">               
 <td><input type="radio" name="group13" value="present[12]">P</input>
     <input type="radio" name="group13" value="Absent[12]">A</input>
	 </fieldset>
	  <fieldset id="group14">               
 <td><input type="radio" name="group14" value="present[13]">P</input>
     <input type="radio" name="group14" value="Absent[13]">A</input>
	 </fieldset>
	  <fieldset id="group15">               
 <td><input type="radio" name="group15" value="present[14]">P</input>
     <input type="radio" name="group15" value="Absent[14]">A</input>
	 </fieldset>
	  <fieldset id="group16">               
 <td><input type="radio" name="group16" value="present[15]">P</input>
     <input type="radio" name="group16" value="Absent[15]">A</input>
	 </fieldset>
	  <fieldset id="group17">               
 <td><input type="radio" name="group17" value="present[16]">P</input>
     <input type="radio" name="group17" value="Absent[16]">A</input>
	 </fieldset>
	 <fieldset id="group18">               
 <td><input type="radio" name="group18" value="present[17]">P</input>
     <input type="radio" name="group18" value="Absent[17]">A</input>
	 </fieldset>
	  <fieldset id="group19">               
 <td><input type="radio" name="group19" value="present[18]">P</input>
     <input type="radio" name="group19" value="Absent[18]">A</input>
	 </fieldset>
	  
</tr>



      <td><input type="submit" name="submit" value="Submit"></td>
   </tr></table>

Open in new window

i made changes to the html file.
Can u help store the data in sql using php?
<html>
<body bgcolor="pink">
<center>
<form method="post">
<table border="1" bgcolor="#00CCFF">

<th>Student Name</th>
    <th>Passport Number</th> 
    <th>VISA</th>
	<th>Class</th>
    <th>Country</th> 
	<th>duration</th>
    <th><P>M<br>
	       02</p></th>
		   <th><P>T<br>
	       03</p></th>
		   <th><P>W<br>
	       04</p></th>
		   <th><P>T<br>
	       05</p></th>
		   <th><P>F<br>
	       06</p></th>
		   
		   <th><P>M<br>
	       09</p></th>
		   <th><P>T<br>
	       10</p></th>
		   <th><P>W<br>
	       11</p></th>
		   <th><P>T<br>
	       12</p></th>
		   <th><P>F<br>
	       13</p></th>
		   
		   <th><P>M<br>
	       16</p></th>
		   <th><P>T<br>
	       17</p></th>
		   <th><P>W<br>
	       18</p></th>
		   <th><P>T<br>
	       19</p></th>
		   <th><P>F<br>
	       20</p></th>
	
	<th><P>M<br>
	       23</p></th>
		   <th><P>T<br>
	       24</p></th>
		   <th><P>W<br>
	       25</p></th>
		   <th><P>T<br>
	       26</p></th>
		   <th><P>F<br>
	       27</p></th>
	
  </tr>
  <td>ANWAR ALMBOK HUSIEN AYOUB</td>
    <td>H1G963P</td>
    <td>N.V</td>
	<td>INT</td>
    <td>LIB</td>
    <td>APR 18-JUN 18</td> 
	<td><input type="radio" name="group1" value="present[0]">P</input>
     <input type="radio" name="group1" value="Absent[0]">A</input>
	

<tr><td><input type="submit" name="submit" value="Submit"/></td></tr>
</table>
</form>
</center>
</body>
</html>

Open in new window

Store it how - what does your table look like?
<html>
<body bgcolor="pink">
<center>
<form method="post">
<table border="1" bgcolor="#00CCFF">

<th>Student Name</th>
    <th>Passport Number</th> 
    <th>VISA</th>
	<th>Class</th>
    <th>Country</th> 
	<th>duration</th>
    <th><P>M<br>
	       02</p></th>
		   <th><P>T<br>
	       03</p></th>
		   <th><P>W<br>
	       04</p></th>
		   <th><P>T<br>
	       05</p></th>
		   <th><P>F<br>
	       06</p></th>
		   
		   <th><P>M<br>
	       09</p></th>
		   <th><P>T<br>
	       10</p></th>
		   <th><P>W<br>
	       11</p></th>
		   <th><P>T<br>
	       12</p></th>
		   <th><P>F<br>
	       13</p></th>
		   
		   <th><P>M<br>
	       16</p></th>
		   <th><P>T<br>
	       17</p></th>
		   <th><P>W<br>
	       18</p></th>
		   <th><P>T<br>
	       19</p></th>
		   <th><P>F<br>
	       20</p></th>
	
	<th><P>M<br>
	       23</p></th>
		   <th><P>T<br>
	       24</p></th>
		   <th><P>W<br>
	       25</p></th>
		   <th><P>T<br>
	       26</p></th>
		   <th><P>F<br>
	       27</p></th>
	
  </tr>
  <td>ANWAR ALMBOK HUSIEN AYOUB</td>
    <td>H1G963P</td>
    <td>N.V</td>
	<td>INT</td>
    <td>LIB</td>
    <td>APR 18-JUN 18</td> 
	<td><input type="radio" name="group1" value="present[0]">P</input>
     <input type="radio" name="group1" value="Absent[0]">A</input>
	

<tr><td><input type="submit" name="submit" value="Submit"/></td></tr>
</table>
</form>
</center>
</body>
</html>

Open in new window


  User generated image
First you would need to give your form an action Example
<form method="post" action="submit.php">

Open in new window


Here is the first problem look at your radio button
<input type="radio" name="group1" value="present[0]">P</input>
<input type="radio" name="group1" value="Absent[0]">A</input>

Open in new window


1. You have an array definition for the value - why? Usually we do that for the name not the value
     What value do you want to insert into the database for group1
2. <input> tags do not have a closing tag. Just do this
    <input name="namehere> type="radio">

Open in new window


In your PHP script you would need to check if you received the parameters
<?php
$group1 = isset($_POST['group1']) ? $_POST['group1'] : false;
if (!$group1) {
  // handle invalid parameter here
}
// Connect to the database
$mysqli = new mysqli($server, $user, $pass, $db);

// Check for connection failure (code not supplied - see docs)

// Build Query using HEREDOC
$query = <<< QUERY
INSERT INTO `tablenamehere` (`fieldname`)
VALUES (?)
QUERY;

// Create a prepared statement
$stmt = $mysqli->prepare($query);

// Check stmt valid (code not provided)

// Bind the group1 value to the query
$stmt->bind_param("s", $group1);

// Execute the query
$stmt->execute();

// Either redirect to page to show after insert
header('location: script.php');
// OR
// Include file to handle output to browser
// require('script.php');
// Depends on requirements.

Open in new window

What does your DATABASE TABLE look like?
the array is because i want to take the attendance different dates in the month and also there are many students.

User generated image
my database

<?php
$link = mysqli_connect("localhost", "root", "", "Attendance");
 
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());}


@$studentName=$_POST['studentName'];
@$passportNumber=$_POST['passportNumber'];
@$visa=$_POST['visa'];
@$class=$_POST['class'];
@$country=$_POST['country'];
@$duration=$_POST['duration'];
@$M_02=$_POST['M_02'];
if(@$_POST['submit'])
{
$sql = "INSERT INTO aprilAttendance (studentName,passportNumber,visa,class,country,duration,M_02 ) VALUES ('$studentName', '$passportNumber','$visa','$class'
,'$country','$duration','$M_02')";
if(mysqli_query($link, $sql)){
    echo "Records added successfully.";
} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
}
// close connection
mysqli_close($link);

Open in new window

I  made changes.
if i set  same "name" for radio buttons, it will select the last one and deselects the previous ones.
Is it possible to have multiple radio button groups in a single form? Usually selecting one button deselects the previous, I just need to have one of a group deselected.


<html>
<body bgcolor="pink">
<center>
<form method="post" action="submit.php">
<table border="1" bgcolor="#00CCFF">

<th>Student Name</th>
    <th>Passport Number</th> 
    <th>VISA</th>
	<th>Class</th>
    <th>Country</th> 
	<th>duration</th>
    <th><P>M<br>
	       02</p></th>
		   <th><P>T<br>
	       03</p></th>
		   <th><P>W<br>
	       04</p></th>
		   <th><P>T<br>
	       05</p></th>
		   <th><P>F<br>
	       06</p></th>
		   
		   <th><P>M<br>
	       09</p></th>
		   <th><P>T<br>
	       10</p></th>
		   <th><P>W<br>
	       11</p></th>
		   <th><P>T<br>
	       12</p></th>
		   <th><P>F<br>
	       13</p></th>
		   
		   <th><P>M<br>
	       16</p></th>
		   <th><P>T<br>
	       17</p></th>
		   <th><P>W<br>
	       18</p></th>
		   <th><P>T<br>
	       19</p></th>
		   <th><P>F<br>
	       20</p></th>
	
	<th><P>M<br>
	       23</p></th>
		   <th><P>T<br>
	       24</p></th>
		   <th><P>W<br>
	       25</p></th>
		   <th><P>T<br>
	       26</p></th>
		   <th><P>F<br>
	       27</p></th>
	
  </tr>
  <td>ANWAR ALMBOK HUSIEN AYOUB</td>
    <td>H1G963P</td>
    <td>N.V</td>
	<td>INT</td>
    <td>LIB</td>
    <td>APR 18-JUN 18</td> 
	 <div id="group1">
	<td><input type="radio" name="group1" value="present">P
     <input type="radio" name="group1" value="Absent">A
	  </div id="group1">
	  
	  <div id="group2">
	 <td><input type="radio" name="group2" value="present">P
     <input type="radio" name="group2" value="Absent">A
	 </div id="group2">
	 
	 <div id="group3">
	 <td><input type="radio" name="group3" value="present">P
     <input type="radio" name="group3" value="Absent">A
	 </div id="group3">
	 
	 <div id="group4">
	 <td><input type="radio" name="group4" value="present">P
     <input type="radio" name="group4" value="Absent">A
	 </div id="group4">
	 <!-- GROUPS REPRESENTS DAYS..EACH GROUP REPRESENTS ONE DAY-->
	 
	</tr>
<tr><td><input type="submit" name="submit" value="Submit"/></td></tr>
</table>
</form>
</center>
</body>
</html>

Open in new window

the array is because i want to take the attendance different dates in the month and also there are many students.
Then you make the name an array not the value - the value will not be interpreted as an array.

if i set  same "name" for radio buttons, it will select the last one and deselects the previous ones.
I don't know what you are asking. Radio buttons work as many options, one select. They are grouped together by the name attribute - radios with the same name will act as a group - selecting any one in the group deselects the previously selected (if any)

Is it possible to have multiple radio button groups in a single form?
Yes each group has the same name for all radio's - it will come through as a single value on the server (the selected value). If you don't select any value in the group then this control will be omitted from the data sent to the server.

Usually selecting one button deselects the previous, I just need to have one of a group deselected.
I don't know what you are saying here.
Thanks a lot. I followed your way.
The problem i have now is, since am having different rows, the last row deselects the previous row.
so how i can make sure the user selects each row on its own. thanks

<html>
<body bgcolor="pink">
<center>
<form method="post" >

<table border="1" bgcolor="#00CCFF">

<th>Student Name</th>
    <th>Passport Number</th> 
    <th>VISA</th>
	<th>Class</th>
    <th>Country</th> 
	<th>duration</th>
    <th><P>M<br>
	       02</p></th>
		   <th><P>T<br>
	       03</p></th>
		   <th><P>W<br>
	       04</p></th>   
	
  </tr>
  
  <tr>
  

  <td>ANWAR ALMBOK HUSIEN AYOUB</td>
    <td>H1G963P</td>
    <td>N.V</td>
	<td>INT</td>
    <td>LIB</td>
    <td>APR 18-JUN 18</td> 
	
	
	
	<td>
    <input type="radio" name="day[]" value="present" checked>P
    <input type="radio" name="day[]" value="absent">A

</td>
<td>
    <input type="radio" name="day[]" value="present" checked>P
    <input type="radio" name="day[]" value="absent">A

</td>
<td>
    <input type="radio" name="day[]" value="present" checked>P
    <input type="radio" name="day[]" value="absent">A
</td>
	</tr>
 

 <tr>
  <td>DIRIE ABDIKANI</td>
    <td>POO348767</td>
    <td>N.V</td>
	<td>INT</td>
    <td>YEM</td>
    <td>APR 18-JUN 18</td> 
	
	<td>
    <input type="radio" name="day[]" value="present" checked>P
    <input type="radio" name="day[]" value="absent">A

</td>
<td>
    <input type="radio" name="day[]" value="present" checked>P
    <input type="radio" name="day[]" value="absent">A
</td>

<td>
    <input type="radio" name="day[]" value="present" checked>P
    <input type="radio" name="day[]" value="absent">A</input>
</td>
	</tr>
 
<tr><td><input type="submit" name="submit" value="Submit"/></td></tr>
</table>
</form>
</center>
</body>
</html>

Open in new window

That is because all your radio buttons (all of them) have the same name.
Remember what I said in my last post - for radio's to be part of the SAME group they have the SAME name - if you want them part of a different group - give them a different name.

In HTML day[] is not interpreted as an array - that only happens when the data gets to PHP - in HTML day[] is no different than radioName or myRadio - the [] are seen as normal characters.

For your code to work you need to give your array indices - so
Group 1 would be
day[0]
Group 2 would be
day[1]
And so on
<html>
<body bgcolor="pink">
<center>
<form method="post" >

<table border="1" bgcolor="#00CCFF">

<th>Student Name</th>
    <th>Passport Number</th> 
    <th>VISA</th>
	<th>Class</th>
    <th>Country</th> 
	<th>duration</th>
    <th><P>M<br>
	       02</p></th>
		   <th><P>T<br>
	       03</p></th>
		   <th><P>W<br>
	       04</p></th>   
	
  </tr>
  
  <tr>
  

  <td>ANWAR ALMBOK HUSIEN AYOUB</td>
    <td>H1G963P</td>
    <td>N.V</td>
	<td>INT</td>
    <td>LIB</td>
    <td>APR 18-JUN 18</td> 
	
	
	
	<td>
    <input type="radio" name="day[0]" value="present" checked>P
    <input type="radio" name="day[0]" value="absent">A

</td>
<td>
    <input type="radio" name="day[1]" value="present" checked>P
    <input type="radio" name="day[1]" value="absent">A

</td>
<td>
    <input type="radio" name="day[2]" value="present" checked>P
    <input type="radio" name="day[2]" value="absent">A
</td>
	</tr>
 

 <tr>
  <td>DIRIE ABDIKANI</td>
    <td>POO348767</td>
    <td>N.V</td>
	<td>INT</td>
    <td>YEM</td>
    <td>APR 18-JUN 18</td> 
	
	<td>
    <input type="radio" name="day[3]" value="present" checked>P
    <input type="radio" name="day[3]" value="absent">A

</td>
<td>
    <input type="radio" name="day[4]" value="present" checked>P
    <input type="radio" name="day[4]" value="absent">A
</td>

<td>
    <input type="radio" name="day[5]" value="present" checked>P
    <input type="radio" name="day[5]" value="absent">A</input>
</td>
	</tr>
 
<tr><td><input type="submit" name="submit" value="Submit"/></td></tr>
</table>
</form>
</center>
</body>
</html>

Open in new window

Hi julian. I finally have my form working. could you help me with the php code to loop through the days and take the value plz?

<table border="1" bgcolor="#00CCFF">
	<tr class="theader">
    <th>Student Name</th>
    <th>Passport Number</th> 
    <th>VISA</th>
	<th>Class</th>
    <th>Country</th> 
    <th><P>M<br>
	       02</p></th>
		   <th><P>T<br>
	       03</p></th>
		   <th><P>W<br>
	       04</p></th>
		   <th><P>T<br>
	       05</p></th>
		   <th><P>F<br>
	       06</p></th>
		   
		   <th><P>M<br>
	       09</p></th>
		   <th><P>T<br>
	       10</p></th>
		   <th><P>W<br>
	       11</p></th>
		   <th><P>T<br>
	       12</p></th>
		   <th><P>F<br>
	       13</p></th>
		   
		   <th><P>M<br>
	       16</p></th>
		   <th><P>T<br>
	       17</p></th>
		   <th><P>W<br>
	       18</p></th>
		   <th><P>T<br>
	       19</p></th>
		   <th><P>F<br>
	       20</p></th>
	
	<th><P>M<br>
	       23</p></th>
		   <th><P>T<br>
	       24</p></th>
		   <th><P>W<br>
	       25</p></th>
		   <th><P>T<br>
	       26</p></th>
		   <th><P>F<br>
	       27</p></th>
	
  </tr>
 



  
  <tr>
  

  <td>ANWAR ALMBOK HUSIEN AYOUB</td>
    <td>H1G963P</td>
    <td>N.V</td>
	<td>INT</td>
    <td>LIB</td>
    <td>APR 18-JUN 18</td> 
	
	

	<td>
    <input type="radio" name="day[0]" value="present" checked>P
    <input type="radio" name="day[0]" value="absent">A

</td>
<td>
    <input type="radio" name="day[1]" value="present" checked>P
    <input type="radio" name="day[1]" value="absent">A

</td>
<td>
    <input type="radio" name="day[2]" value="present" checked>P
    <input type="radio" name="day[2]" value="absent">A
</td>
<td>
    <input type="radio" name="day[3]" value="present" checked>P
    <input type="radio" name="day[3]" value="absent">A
</td>
<td>
    <input type="radio" name="day[4]" value="present" checked>P
    <input type="radio" name="day[4]" value="absent">A
</td>
<td>
    <input type="radio" name="day[5]" value="present" checked>P
    <input type="radio" name="day[5]" value="absent">A
</td>
<td>
    <input type="radio" name="day[6]" value="present" checked>P
    <input type="radio" name="day[6]" value="absent">A
</td>
<td>
    <input type="radio" name="day[7]" value="present" checked>P
    <input type="radio" name="day[7]" value="absent">A
</td>
<td>
    <input type="radio" name="day[8]" value="present" checked>P
    <input type="radio" name="day[8]" value="absent">A
</td>
<td>
    <input type="radio" name="day[9]" value="present" checked>P
    <input type="radio" name="day[9]" value="absent">A
</td>
<td>
    <input type="radio" name="day[10]" value="present" checked>P
    <input type="radio" name="day[10]" value="absent">A
</td>
<td>
    <input type="radio" name="day[11]" value="present" checked>P
    <input type="radio" name="day[11]" value="absent">A
</td>
<td>
    <input type="radio" name="day[12]" value="present" checked>P
    <input type="radio" name="day[12]" value="absent">A
</td>
<td>
    <input type="radio" name="day[13]" value="present" checked>P
    <input type="radio" name="day[13]" value="absent">A
</td>
<td>
    <input type="radio" name="day[14]" value="present" checked>P
    <input type="radio" name="day[14]" value="absent">A
</td>
<td>
    <input type="radio" name="day[15]" value="present" checked>P
    <input type="radio" name="day[15]" value="absent">A
</td>
<td>
    <input type="radio" name="day[16]" value="present" checked>P
    <input type="radio" name="day[16]" value="absent">A
</td>
<td>
    <input type="radio" name="day[17]" value="present" checked>P
    <input type="radio" name="day[17]" value="absent">A
</td>
<td>
    <input type="radio" name="day[18]" value="present" checked>P
    <input type="radio" name="day[18]" value="absent">A
</td>



	</tr>
 

 <tr>
  <td>DIRIE ABDIKANI</td>
    <td>POO348767</td>
    <td>N.V</td>
	<td>INT</td>
    <td>YEM</td>
    <td>APR 18-JUN 18</td> 
	
	<td>
    <input type="radio" name="day[19]" value="present" checked>P
    <input type="radio" name="day[19]" value="absent">A

</td>
<td>
    <input type="radio" name="day[20]" value="present" checked>P
    <input type="radio" name="day[20]" value="absent">A
</td>

<td>
    <input type="radio" name="day[21]" value="present" checked>P
    <input type="radio" name="day[21]" value="absent">A</input>
</td>
<td>
    <input type="radio" name="day[22]" value="present" checked>P
    <input type="radio" name="day[22]" value="absent">A</input>
</td>


<td>
    <input type="radio" name="day[23]" value="present" checked>P
    <input type="radio" name="day[23]" value="absent">A</input>
</td>
<td>
    <input type="radio" name="day[24]" value="present" checked>P
    <input type="radio" name="day[24]" value="absent">A</input>
</td>
<td>
    <input type="radio" name="day[25]" value="present" checked>P
    <input type="radio" name="day[25]" value="absent">A</input>
</td>
<td>
    <input type="radio" name="day[26]" value="present" checked>P
    <input type="radio" name="day[26]" value="absent">A</input>
</td>

<td>
    <input type="radio" name="day[27]" value="present" checked>P
    <input type="radio" name="day[27]" value="absent">A</input>
</td>


<td>
    <input type="radio" name="day[28]" value="present" checked>P
    <input type="radio" name="day[28]" value="absent">A</input>
</td>
<td>
    <input type="radio" name="day[29]" value="present" checked>P
    <input type="radio" name="day[29]" value="absent">A</input>
</td>
<td>
    <input type="radio" name="day[30]" value="present" checked>P
    <input type="radio" name="day[30]" value="absent">A</input>
</td>
<td>
    <input type="radio" name="day[31]" value="present" checked>P
    <input type="radio" name="day[31]" value="absent">A</input>
</td>

<td>
    <input type="radio" name="day[32]" value="present" checked>P
    <input type="radio" name="day[32]" value="absent">A</input>
</td>

<td>
    <input type="radio" name="day[33]" value="present" checked>P
    <input type="radio" name="day[33]" value="absent">A</input>
</td>


<td>
    <input type="radio" name="day[34]" value="present" checked>P
    <input type="radio" name="day[34]" value="absent">A</input>
</td>
<td>
    <input type="radio" name="day[35]" value="present" checked>P
    <input type="radio" name="day[35]" value="absent">A</input>
</td>
<td>
    <input type="radio" name="day[36]" value="present" checked>P
    <input type="radio" name="day[36]" value="absent">A</input>
</td>
<td>
    <input type="radio" name="day[37]" value="present" checked>P
    <input type="radio" name="day[37]" value="absent">A</input>
</td>
	</tr>
 
<tr><td><input type="submit" name="submit" value="Submit"/></td></tr>
</table>
</form>
</center>

Open in new window

I made this php script but it is inserting empty records.

@$studentName=$_POST['studentName'];
@$passportNumber=$_POST['passportNumber'];
@$visa=$_POST['visa'];
@$class=$_POST['class'];
@$country=$_POST['country'];
@$duration=$_POST['duration'];


@$M_02 =  $_REQUEST['M_02 '];
@$T_03 =  $_REQUEST['T_03 '];
@$W_04 =  $_REQUEST['W_04 '];
@$T_05 =  $_REQUEST['T_05 '];
@$F_06 =  $_REQUEST['F_06'];

@$M_09 =  $_REQUEST['M_09 '];
@$T_10 =  $_REQUEST['T_10 '];
@$W_11 =  $_REQUEST['W_11 '];
@$T_12 =  $_REQUEST['T_12 '];
@$F_13=  $_REQUEST['F_13 '];

@$M_16 =  $_REQUEST['M_16 '];
@$T_17 =  $_REQUEST['T_17 '];
@$W_18 =  $_REQUEST['T_18 '];
@$T_19 =  $_REQUEST['T_19 '];
@$F_20 =  $_REQUEST['T_20'];

@$M_23 =  $_REQUEST['M_23 '];
@$T_24 =  $_REQUEST['T_24 '];
@$W_25 =  $_REQUEST['W_25 '];
@$T_26 =  $_REQUEST['T_26 '];
@$F_27 =  $_REQUEST['F_27 '];

	
	if(@$_POST['submit']){
	$sql = "INSERT INTO aprilattendance (studentName, passportNumber, class,country,duration,M_02,T_03,W_04,T_05,F_06,
	 M_09,T_10,W_11,T_12,F_13,M_16,T_17,W_18,T_19,F_20,M_23,T_24,W_25,T_26,F_27) 
	  VALUES('$studentName','$passportNumber','$visa','$class','$country','$duration','$M_02',' $T_03',' $W_04',' $T_05','$F_06',
	 '$M_09','$T_10 ','$W_11','$T_12',' $F_13','$M_16','$T_17',' $W_18','$T_19',' $F_20',
	 '$M_23','$T_24','$T_26','$F_27')";

Open in new window

How does
 $_REQUEST['M_02 '];

Open in new window

Relate to your form?

Firstly, don't use REQUEST - if you are posting to your script use POST.
Secondly, your radio's are stored as an array

If we had your database schema from the beginning it would have made this a bit easier.

What I would do is make your naming of your controls match your database. This means making the names of your controls the same as the fields in your table.

Let's look at your PHP code again
@$M_02 =  $_REQUEST['M_02 '];
^ why?

Open in new window

Suppressing errors is a very bad practice the correct way of getting your variables out of post is like so
// PUT YOUR DEFAULT VALUE YOU WANT WHERE THE '' IS IF YOU DON'T WANT A BLANK STRING
$M_02 = isset($_POST['M_02']) ? $_POST['M_02'] : ''; 

Open in new window

Then
@$M_02 =  $_REQUEST['M_02 '];
                         ^ why?

Open in new window

A space in code is just like any character 'M_02' is not equal to 'M_02 ' - you will never find your variables if you add spaces to the end of their names.

You can use arrays for your radio's but given your table structure and your current skill level I will say don't use them for now - rather name your groups according to your Table's field names, make the changes to your code I have recommended above and try again.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.