ID 为特定学生。在 profilePage.-6ren">
gpt4 book ai didi

php - ID 不响应学生姓名的 URL 查询

转载 作者:行者123 更新时间:2023-11-29 01:37:51 24 4
gpt4 key购买 nike

我在一个页面上有一个表格,用户点击一个大学生,然后将他们带到他们的个人资料页面。该个人资料由

链接
<a href="profilePage.php?id=<?php echo $row['ID'] ?>" class="collection-item">

ID 为特定学生。在 profilePage.php 上,它在 URL 上显示了 id,但没有打印出学生的姓名。它只是空白,“学生姓名是”

<?php
$idStudent = mysql_real_escape_string($_GET['ID']);
$sql = sprintf("SELECT * FROM student_info WHERE id = %s", $idStudent);
$query = mysql_query($sql);
$student = mysql_fetch_object($query);
?>

<p>Student name is <?php echo $student['student_Name'] ?></p>

我假设这就是我调用 id 然后从数据库查询的方式。我正在使用 phpMyAdmin。这是我连接到数据库的方式

<?php
$db = mysql_connect("localhost","server","password");
if (!$db) {
die("Database connection failed miserably: " . mysql_error());
}
$db_select = mysql_select_db("name",$db);
if (!$db_select) {
die("Database selection also failed miserably: " . mysql_error());
}

同样的问题是,即使我在 url 中有 ID,profilePage.php 也没有回应学生姓名。

最佳答案

您的网址是 id=<?php echo $row['ID'] ?>你正在使用 $_GET['ID']在你的代码中弄错$_GET['id']!=$_GET['ID'] .You can get your id as

$idStudent = mysql_real_escape_string($_GET['id']);// use small id instead id ID

您正在 object form 中获取数据

$student = mysql_fetch_object($query);

所以不是这个

  <p>Student name is <?php echo $student['student_Name'] ?></p>

使用

<p>Student name is <?php echo $student->student_Name; ?></p>

Note:- mysql is deprecated instead use mysqli OR PDO

关于php - ID 不响应学生姓名的 URL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34939464/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com