从数据库中提取数据并使用php以表单形式显示

从数据库中提取数据并使用php以表单形式显示,php,mysql,forms,mysqli,Php,Mysql,Forms,Mysqli,我创建了两个PHP文件,并将其放在localhost的同一文件夹中。 第一个文件从数据库中提取数据并将其显示在表中。我创建了编辑选项,所以当我单击它时,它会将我指向表单中显示所选id数据的其他页面 但它不起作用。数据以表格的形式显示,但当我单击“编辑”时,它什么也不做。它并没有把我引向第二页 第一个文件代码: <table border="2"> <tr> <th>Roll_No</th> <th>

我创建了两个PHP文件,并将其放在localhost的同一文件夹中。 第一个文件从数据库中提取数据并将其显示在表中。我创建了编辑选项,所以当我单击它时,它会将我指向表单中显示所选id数据的其他页面

但它不起作用。数据以表格的形式显示,但当我单击“编辑”时,它什么也不做。它并没有把我引向第二页

第一个文件代码:

<table border="2">
    <tr>
        <th>Roll_No</th>
        <th>Name</th>
        <th> Class</th>
        <th>Marks</th>
        <th> Edit </th>
    </tr>
<?php
     $conn=mysqli_connect("localhost","root","","cs_dpt");
     $q2="select * from students";
     $run=mysqli_query($conn, $q2);
     while($row=mysqli_fetch_array($run))
     {
         $id=$row[0];
         $name=$row[1];
         $class=$row[2];
         $section=$row[3];
     ?>
    <tr>
        <td><?php echo $id; ?></td>
        <td><?php echo $name; ?></td>
        <td><?php echo $class; ?></td>
        <td><?php echo $section; ?></td>
        <td><a href="edit.php?edit=<?php echo $id; ?>"> Edit </a></td>
    </tr>
 <?php } ?>
 </table> 

卷号
名称
等级
标志
编辑
edit.php

<?php
    $conn=mysqli_connect("localhost","root","","cs_dpt");
    $edit=$_GET['edit'];
    $q="select from students where roll_no='$edit'";
    $run=mysqli_query($conn, $q);
    while($row=mysqli_fetch_array($run)){
        $roll_no=$row[0];
        $name=$row[1];
        $class=$row[2];
        $section=$row[3];
    }
?>
    <form>
        Roll No:<input type="text" name="roll_no" value="<?php echo $roll_no; ?>">
        Name:<input type="text" name="name" value="<?php echo $name; ?>">
        Class:<input type="text" name="class" value="<?php echo $class; ?>">
        Section:<input type="text" name="marks" value="<?php echo $section; ?>">
        <button type="button" name="button"><a href=""> Update Record</a></button>
        <br><br>
    </form>
<?php
header("Location:practise.php");
?>

选择查询中缺少
*

$q="select from students where roll_no='$edit'";
是的

$q="select * from students where roll_no='$edit'";
并使用
MYSQLI_NUM
获取数字数组

 $run=mysqli_query($conn, $q);
    while($row=mysqli_fetch_array($run,MYSQLI_NUM)){
        $roll_no=$row[0];
        $name=$row[1];
        $class=$row[2];
        $section=$row[3];
    }

阅读

只是一个打字错误。将查询更改为“选择*来自卷号为“$edit”的学生”使用select*或select field1、field2…..此外,确保将相同的卷号传递给编辑。希望您的表中有相同的字段名。是的,我在表中有相同的字段名。我已经尝试了两个查询“从roll_no='$edit'的学生中选择”和“从roll_no='$edit'的学生中选择*”,但都不起作用。好的,您能回显
$edit=$\u GET['edit']在编辑页面??它的价值是什么?在获取数据的第一个文件代码中使用
mysqli\u fetch\u数组($run,mysqli\u NUM)
否,当我单击编辑选项时,我无法直接编辑页面,不会发生任何事情。我已经编辑了我的代码并使用了“mysqli_fetch_array($run,mysqli_NUM)”仍然不起作用。首先,在while循环中pare print_r($row)并使用
mysqli_fetch_array($run,mysqli_NUM)