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.

    ?> <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> 

$regn=$_POST['regn'];//here getting result from the post array after submitting the form.

echo "<script>alert('Subject Name $subject_name1 with Subject Code $subject_code1 is already registered')</script>";

$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')";

echo "<script>alert('You have Succesfully registered $subject_code1 - $subject_name1 ')</script>";


?> </table>

Edited by Anni_2

1 Year
Discussion Span
Last Post by hericles

If you're referring to this bit:

while($row=mysqli_fetch_array($run))//while look to fetch the result and store in a array $row.

you're setting the variables $slno, $sem, $subject_code and $subject_name on each loop through but doing nothing with them. On the next loop you're setting them again and, again, doing nothing with the new values.
Only on the last loop do you move on to the next piece of code and actually output the values.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.