无法从服务器

时间:2017-02-12 06:07:51

标签: php mysql mysqli

这是我将数据发送到表中的代码,工作正常**

<?php

if($_SERVER["REQUEST_METHOD"]=="POST"){

    require 'connection.php';
    createStudent();

}
function createStudent()
{
    global $connect;

    $firstname = $_POST["firstname"];
    $lastname = $_POST["lastname"];
    $age = $_POST["age"];

    $query = " Insert into student(firstname,lastname,age) values ('$firstname', '$lastname', '$age');";

    mysqli_query($connect, $query) or die (mysqli_error($connect));
    mysqli_close($connect);
}
?>`

但每当我尝试获取数据时,它都不会显示任何内容。

我获取数据的代码如下:

<?php

if($_SERVER["REQUEST_METHOD"]=="POST"){
    include 'connection.php';
    showStudent();
} 

function showStudent()
{
    global $connect;

    $query = " Select * FROM STUDENT; ";

    $result = mysqli_query($connect, $query);
    $number_of_rows = mysqli_num_rows($result);

    $temp_array  = array();

if($number_of_rows > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        $temp_array[] = $row;
    }
}

header('Content-Type: application/json');
echo json_encode(array("students"=>$temp_array));
mysqli_close($connect);

}
?>

请帮我从表格中取出行。 我的感觉是......它无法将数据存储到数组中!

0 个答案:

没有答案