【发布时间】:2017-04-25 05:03:52
【问题描述】:
这是我的整个 html 和 php 代码
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h2>Student Details</h2>
<div id="EditStudent">
<a href="UpdateStudent.php?SelectionId=$Carrier"><img src="sawiro/EditImage.jpg" alt="Edit Student Image"></a>
</div>
<table style="width: 100%" border ="0" bordercolor="green" bgcolor="white" cellspacing="20" cellpadding="0">
<thead>
<tr>
<?php
$Carrier = 0;
function clearInput($data){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if(isset($_GET['SelectedId'])){
$Carrier = clearInput($_GET['SelectedId']);
}
$cnx = new PDO('mysql:host=localhost;dbname=transportsystem;charset=utf8', 'root', '');
$result = $cnx->query("SELECT * FROM person
INNER JOIN student ON person.PerID = student.StPersonID
WHERE PerID = $Carrier");
while($row = $result->fetch()){
$Name = $row["Name"];
$Gender = $row["Gender"];
$Telephone = $row["Telephone"];
$Class = $row["Class"];
echo '<th colspan="8" style="font-size:40px;">'.$row["Name"].'</th>';
}
?>
</tr>
</thead>
<tr style="color: #000;">
<th> Student ID:</th>
<td><?php echo $Carrier;?></td>
</tr>
<tr>
<th> Full Name:</th>
<td><?php echo $Name;?></td>
</tr>
<tr>
<th> Gender:</th>
<td><?php echo $Gender;?></td>
</tr>
<tr>
<th> Telephone:</th>
<td><?php echo $Telephone;?></td>
</tr>
<tr>
<th> Class:</th>
<td><?php echo $Class;?></td>
</tr>
</table>
</body>
</html>
我想添加Selectionid,你可以在上面看到
?SelectionId=$Carrier;
因为这段代码,我的 id 变量是 $Carrier
if(isset($_GET['SelectedId']))
{$Carrier = clearInput($_GET['SelectedId']);}
我想在点击<img src="sawiro/EditImage.jpg" alt="Edit Student Image"> 后给我网址UpdateStudent.php?SelectionId=8,例如,使用此ID 来设置数据。
请帮助我从目标 php 收集 id 以用于另一个 php 以更新该特定行。
【问题讨论】:
-
不确定
?SelectionId='."$Carrier".';"应该做什么。如果要在字符串中添加 ID,则需要添加一个 php 块:"UpdateStudent.php?SelectionId=<?= $Carrier ?>"(这是 PHP 101)。如果这不是问题,您需要澄清您的问题,因为它非常不清楚您实际在问什么。 -
您将在哪里获得
$_GET['SelectedId']? -
$Carrier永远不会有值,因为您的代码中似乎缺少$_GET['SelectedId'] -
没有丢失,在if语句中可以看到
-
我的意思是你会从哪里得到
$_GET['SelectedId']?没有它,$Carrier将永远没有价值。我建议你检查你的代码流,并检查错别字