2017-09-18 11 views
0

下の画像を参照してください。 Image 登録ボタンをクリックすると、必要な行の代わりに最後の行が挿入されます。各行に挿入ボタンを作成する方法は?

私が必要とするのは:私がクリックすると、選択した行全体が別のテーブルに保存されている必要があります。

ここで何が間違っていますか? 私を助けてください..

<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

は、私はあなたがあなたのif文に目を通すことをお勧めします。それは言う:

行は0、より多くのであれば、アウトエコー:

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

その後、あなたはどこにもそれがif文か何かの下にある場合を指していないと、単に{}であなたの挿入行を持っています。

+0

これは、インセット関数の回数を制限することです –

+0

クエリではLIMIT = 1で制限できます。それは、それをその時点で1つのアイテムに限定することになります。 – Cordux

関連する問題