Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何用php在网页中显示整个数据库存储的记录?_Php - Fatal编程技术网

如何用php在网页中显示整个数据库存储的记录?

如何用php在网页中显示整个数据库存储的记录?,php,Php,Form.html <html> <head><title>PHP Form</title> </head> <body bgcolor = "#b3ffff"> <div> <h1 align = "center" border = "5">Dream media solution</h1>

Form.html

<html>
    <head><title>PHP Form</title>
            </head>

    <body bgcolor = "#b3ffff">

        <div>
            <h1 align = "center" border = "5">Dream media solution</h1>
        </div><br>
            <div>
        <form method = "post" action = "welcome.php">

            <table width = "640" align = "center" border = "5" border-color = "red">





            <tr>
                <th>Name:</th>
                <th><input type = "text" name = "uname" placeholder = "Enter ur Name" size="28"></th>
            </tr>
            <tr>
                <th>Email:</th>
                <th><input type = "email" name = "uemail" placeholder = "Enter ur Email" size="28"></th>
                </tr>
                <tr>
                <th>Password:</th>
                <th><input type = "password" name = "upass" placeholder = "Enter ur Password" size="28"></th>
                </tr>
                <tr>
                <th>Address:</th>
                <th><textarea size="26" name="address" rows="3" cols="26"></textarea></th>
                </tr>
                <tr>
                <th>Gender:</th>
                <th><input type="radio" name="gender" value="female">Female
                        <input type="radio" name="gender" value="male">Male</th>    
                </tr>
                <tr>
                <th>Course:</th>
                        <th><input type="checkbox" name="course[]" value="PHP">PHP
                        <input type="checkbox" name="course[]" value="Java">Java
                        <input type="checkbox" name="course[]" value=".NET">.NET
                        <input type="checkbox" name="course[]" value="Web Designing">Web Designing</th>
                        </tr>
                    <tr>
                        <td colspan = "2" align = "center"><input type = "submit" value  = "login" name = "subname">
                            <input type = "reset" value = "clear"><td>
                    </tr>

            </table>

        </form>
        </div>
    </body>
    </html>

PHP表单
梦想媒体解决方案

姓名: 电邮: 密码: 地址: 性别: 女性 男性 课程: PHP JAVA .NET 网页设计
welcome.php

<body bgcolor = "pink">
<font size = "6" color = "yellow">
    <?php

    if (isset($_POST['subname'])) 
    {
        $counter = 1;
        $name = $_POST['uname'];
        $email = $_POST['uemail'];
        $pass = $_POST['upass'];
        $gender = $_POST['gender'];
         $cou = implode(",", $_POST['course']);

         $address = $_POST['address'];
         //Database connection
        $con = mysqli_connect("localhost", "root", "");
        // create databse
        mysqli_query($con, "CREATE DATABASE sms");
        //select database
        mysqli_select_db($con, "sms");

        //Create table
        $ct = "CREATE TABLE student1(sno INTEGER(3) AUTO_INCREMENT PRIMARY KEY, 
        name VARCHAR(20), email VARCHAR(20), password VARCHAR(20), address VARCHAR(50), gender VARCHAR(30), course VARCHAR(30))";
        //Excute table through database
        mysqli_query($con,$ct);
        //Insert records into table through database
        $res = mysqli_query($con, "INSERT INTO student1 VALUES('', '$name', '$email', '$pass','$address', '$gender', '$cou')");
        echo "<table width = '640' align = 'center' border = '5' bordercolor = 'red' bgcolor='green' cellpadding = '12'>";
        $result  = mysqli_query($con, "SELECT * FROM student1");
        print_r ($result);
        echo "<tr>";
        echo "<th>Sno</th>";
        echo "<th>Name</th>";
        echo "<th>Email</th>";
        echo "<th>Password</th>";
        echo "<th>Address</th>";
        echo "<th>Gender</th>";
        echo "<th>Course</th>";
        echo "<tr>";
        echo "<th>".$counter."</th>";
        echo "<th>".$_POST['uname']."</th>";
        echo "<th>".$_POST['uemail']."</th>";
        echo "<th>".$_POST['upass']."</th>";
        echo "<th>".$_POST['address']."</th>";
        echo "<th>".$_POST['gender']."</th>";
        echo "<th>".$cou."</th>";

        echo "</tr>";
        echo "</table>";
        if ($res) {
            $msg = "Student Details uploaded successfully";
        }

        else
        {
            $msg = "There is Error in Details please checkout";
        }






            }
    ?>
</font>

我的数据库名是sms,表名是student1

在这里,我只得到一个记录在网页上显示


但我需要数据库中的所有记录,我将在网页中循环并显示这些记录,如何可能,请帮助我。

如果要显示所有数据库记录,请尝试以下代码:

    echo "<table width = '640' align = 'center' border = '5' bordercolor = 'red' bgcolor='green' cellpadding = '12'>";
    $result  = mysqli_query($con, "SELECT * FROM student1");


    echo "<tr>";
    echo "<th>Sno</th>";
    echo "<th>Name</th>";
    echo "<th>Email</th>";
    echo "<th>Password</th>";
    echo "<th>Address</th>";
    echo "<th>Gender</th>";
    echo "<th>Course</th>";
    echo "</tr>";

    $i = 1;
    while($row = mysql_fetch_assoc($result)){        
            echo "<tr>";
            echo "<th>".$i."</th>";
            echo "<th>".$row['name']."</th>";
            echo "<th>".$row['email']."</th>";
            echo "<th>".$row['password']."</th>";
            echo "<th>".$row['address']."</th>";
            echo "<th>".$row['gender']."</th>";
            echo "<th>".$row['course']."</th>";
            echo "</tr>";
    $i++;
    }
    echo "</tr>";
    echo "</table>";
echo”“;
$result=mysqli_查询($con,“从student1中选择*);
回声“;
回声“Sno”;
呼应“姓名”;
回应“电子邮件”;
回显“密码”;
回音“地址”;
呼应“性别”;
呼应“路线”;
回声“;
$i=1;
而($row=mysql\u fetch\u assoc($result)){
回声“;
回显“$i”;
回显“$row['name']”;
回显“$row['email']”;
回显“$row['password']”;
回显“$row['address']”;
回显“$row['gender']”;
回显“$row['course']”;
回声“;
$i++;
}
回声“;
回声“;
使用while循环{}

  <?php
 $sql=$con,"SELECT * FROM student1";
$i = 1;
 $select = mysql_query($sql);
 while($row = mysql_fetch_assoc($select)){ 

 // Set your Values

 $i++;

    }       ?>


请参阅

通过添加循环或动态循环来显示内容,从而在显示(表单html)页面上进行更改。。。使用此代码并根据其进行更改

//创建连接

如果($conn->connect\U错误)死亡(“连接失败:”.$conn->connect\U错误)$sql=“从MyGuests中选择id、firstname、lastname”$结果=$conn->query($sql);if($result->num_rows>0)//输出每行的数据,而($row=$result->fetch_assoc())则返回“
id:”$行[“id”]。“-名称:”$行[“名字”]。" " . $行[“lastname”]。“
”;