• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

如何在php中显示自动增量数据表格mysql

php 来源:Imran Qamar 8次浏览

在我的大学数据库项目中,我的SQL中有一个自动增量字段滚动编号。我想要的是,当新录取发生并插入学生记录时,它会在同一页面上显示所有发现,包括卷号。然而,尽管我尽了最大的努力,但它在卷号中返回0。如何在php中显示自动增量数据表格mysql

下面是代码:

<?php 

$con = mysqli_connect("localhost", "root", "") or die("conection error"); 
mysqli_select_db($con, "hamdard university") or die("dbase error"); 

if (isset($_POST['subbtn'])) { 

    $r  = "SELECT RollNo FROM admission_form"; 
    $result = mysqli_query($con, $r); 
    if (mysqli_query($con, $r)) { 
     $last_id = mysqli_insert_id($con); 
    } 


    $n = $_POST['txtname']; 
    $f = $_POST['txtfac']; 
    $s = $_POST['txtsem']; 

    $sql = "insert into admission_form(name,faculty,semester)values    ('$n','$f','$s')"; 
    mysqli_query($con, $sql); 



    echo "<table border=1> 
      <th>RollNo</th> 
      <th>Name</th> 
      <th>Faculty</th> 
      <th>Semester</th>"; 



    echo "<tr>"; 

    echo "<td>"; 
    echo $last_id; 
    echo "</td>"; 

    echo "<td>"; 
    echo $n; 
    echo "</td>"; 

    echo "<td>"; 
    echo $f; 
    echo "</td>"; 

    echo "<td>"; 
    echo $s; 
    echo "</td>"; 

    echo "<br>"; 


} 
?> 

<html> 

<head></head> 

<body> 
    <form name="f1" action="" method="POST"> 
     RollNo: 
     <input type="text" name="txtroll" readonly> Name: 
     <input type="text" name="txtname"> Faculty: 
     <input type="text" name="txtfac"> Semester: 
     <input type="text" name="txtsem"> 
     <input type="submit" value="done" name="subbtn"> 
    </form> 
</body> 

</html> 


===========解决方案如下:

你需要得到$ last_id INSERT查询

$sql="insert into admission_form(name,faculty,semester)values ... 
mysqli_query($con,$sql); 
$last_id = mysqli_insert_id($con); 

版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)