Whenever i execute this, only the last row of the loop gets inserted even if i click on the first row or any row.
What i need is: if i click register, the entire selected row must store in another table
Whats wrong here?
Please help me..
<table class="table table-striped jambo_table table-bordered"> <thead> <tr> <th width="75px">Semester:</th> <th width="110px">Subject Code:</th> <th>Subject Name:</th> <th width="110px">Exam Type:</th> <th width="110px">Marks:</th> <th width="75px">Action:</th> </tr> </thead> <?php
$view_users_query="select * from details WHERE regd_no='" .$_SESSION['regd_no']. "'";//select query for viewing users.
$run=mysqli_query($dbcon,$view_users_query);//here run the sql query.
while($row=mysqli_fetch_array($run))//while look to fetch the result and store in a array $row.
{
$slno=$row[0];
$sem=$row[5];
$subject_code=$row[9];
$subject_name=$row[10];
?> <tr>
<td><input type="text" class="form-control" readonly="yes" name="sem1" id="sem1" value="<?php echo $sem;?>"></td>
<td><input type="text" class="form-control" readonly="yes" name="subject_code1" id="subject_code1" value="<?php echo $subject_code; ?>"></td>
<td ><input type="text" class="form-control" readonly="yes" name="subject_name1" id="subject_name1" value="<?php echo $subject_name; ?>"></td>
<td> <select class="form-control" id="etype" name="etype"> <option value="">Select-Exam-Type</option>
<option value="Backlog">Backlog</option>
<option value="Improvement">Improvement</option>
<option value="Special Exam">Special Exam</option>
</select> </td>
<td><select class="form-control" id="marks" name="marks"> <option value="">Marks</option>
<option value="100">100</option>
<option value="60">60</option>
<option value="30">30</option> </select></td>
<td> <input type="submit" name="register/<?php echo $subject_code?>" class="btn btn-success form-control" value="Register" > </td>
<!--btn btn-danger is a bootstrap button to show danger--> </tr>
<?php
}
?><br>
<?php
if(isset($_POST['register']))
{
$regn=$_POST['regn'];//here getting result from the post array after submitting the form.
$name=$_POST['name'];//same
$branch=$_POST['branch'];
$batch=$_POST['batch'];
$email=$_POST['email'];
$mobile=$_POST['mobile'];
$center=$_POST['center'];
$date=$_POST['date'];
$sem1=$_POST['sem1'];
$subject_code1=$_POST['subject_code1'];
$subject_name1=$_POST['subject_name1'];
$etype=$_POST['etype'];
$marks=$_POST['marks'];
if(mysqli_num_rows($run_query)>0)
{
echo "<script>alert('Subject Name $subject_name1 with Subject Code $subject_code1 is already registered')</script>";
exit();
}
}
$insert_user="insert into registered (regd_no,name,branch,batch,email,mobile,center,sem,subject_code,subject_name,date,etype,marks) VALUE ('$regn','$name','$branch','$batch','$email','$mobile','$center','$sem1','$subject_code1','$subject_name1','$date','$etype','$marks')";
if(mysqli_query($dbcon,$insert_user))
{
echo "<script>alert('You have Succesfully registered $subject_code1 - $subject_name1 ')</script>";
echo"<script>window.open('','_self')</script>";
}
}
?> </table>