见下图。 当我点击任何注册按钮时,最后一行被插入而不是我需要的行。
我需要的是:如果我点击注册,整个选定的行必须存储在另一个表中。
这里有什么不对? 请帮帮我..
<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'];
}
$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>
答案 0 :(得分:0)
我建议你查看你的if语句。它说:
如果行数大于0,则回显:
<script>alert('Subject Name $subject_name1 with Subject Code $subject_code1 is already registered')</script>
然后你在{}中有你的插入行,无处指向它是否在if语句或任何东西下。