You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GET请求表单无输出排查:MySQL查询有效但页面无显示

Hey there! Let's dig into why your Roster.php page is coming up blank after form submission—even though your query works in phpMyAdmin. This is a super common issue, and it usually boils down to silent errors or missing checks in your PHP code. Let's break it down step by step, covering both the fixes and why each problem happens:

Troubleshooting Your Blank Roster.php Page

1. First, Reveal Hidden Errors

Blank pages almost always mean PHP is suppressing error messages by default. Add these lines to the very top of Roster.php to see exactly what's breaking:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

This will unmask issues like database connection failures, syntax errors in your query, or undefined variables that are stopping execution before any output is sent.

2. Verify Your Database Connection in Roster.php

Just because your form page has a working $con connection doesn't mean Roster.php does. Make sure Roster.php includes the full connection code, and that it's successful:

$con = mysqli_connect("localhost", "your_username", "your_password", "your_database");
if (!$con) {
    die("Connection failed: " . mysqli_connect_error());
}

If the connection fails here, PHP will stop running immediately—no error message, just a blank page—unless you have error reporting turned on.

3. Check if You're Actually Using the GET Parameter

Your form sends a course value via GET, but you need to confirm Roster.php is retrieving it correctly. Always check if the parameter exists before using it in your query:

if (!isset($_GET['course'])) {
    echo "Please select a course first!";
    exit;
}
$selected_course = $_GET['course'];

If you skip this check (say, someone visits Roster.php directly without submitting the form), your query will break silently, leading to a blank page.

4. Fix Your Dynamic Query (Even if the Static One Works)

Your static query works in phpMyAdmin, but when you plug in the GET parameter, you might run into syntax issues or SQL injection risks. Always escape the parameter first:

$selected_course = mysqli_real_escape_string($con, $_GET['course']);
$query = "SELECT teaching.Course_ID, ... FROM teaching WHERE teaching.Course_ID = '$selected_course'";
$result = mysqli_query($con, $query);

// Check if the query ran successfully
if (!$result) {
    die("Query failed: " . mysqli_error($con));
}

For even better safety and reliability, use prepared statements (they eliminate syntax issues from special characters and prevent SQL injection):

$stmt = mysqli_prepare($con, "SELECT teaching.Course_ID, ... FROM teaching WHERE teaching.Course_ID = ?");
mysqli_stmt_bind_param($stmt, "s", $_GET['course']); // Use "i" instead of "s" if Course_ID is an integer
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);

5. Handle "No Results" Cases

Even if your query runs perfectly, if there are no matching rows, you might not output anything. Add a check to cover this:

if (mysqli_num_rows($result) === 0) {
    echo "No students found for this course.";
} else {
    // Loop through results and display your data
    while ($row = mysqli_fetch_assoc($result)) {
        echo "<p>" . $row['Course_ID'] . ": " . $row['Student_Name'] . "</p>";
    }
}

This way, you'll see a message instead of a blank page when there's no data to show.

Why This Happens Even When Your PhpMyAdmin Query Works

  • Missing dynamic values: PhpMyAdmin uses a static value, but your PHP code might be using an undefined or incorrectly formatted variable from the GET request.
  • Unescaped special characters: If your course ID has quotes or backslashes, the static query works in PhpMyAdmin, but the dynamic PHP query breaks because those characters mess with SQL syntax.
  • Disconnected code: Your form page might have a valid database connection, but Roster.php doesn't include that connection code, leading to a silent failure.
  • Error suppression: PHP's default settings hide errors, so you can't see the actual problem causing the blank page.

Once you implement these checks, you should be able to spot and fix the issue right away.

内容的提问来源于stack exchange,提问作者A. Shawkat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:11:13