這是我的整個HTML和PHP代碼如何在php中單擊圖像鏈接更新頁面時收集id?
<!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標識中使用另一個PHP來更新特定行。
不知道什麼'SelectionId =「‘$承運人’。」;「'是假設做,如果你想要的ID添加到?字符串,你需要添加一個php塊:''UpdateStudent.php?SelectionId = <?= $ Carrier?>「'(這是PHP 101)如果這不是問題,你需要澄清你的問題,因爲它是_very_不清楚你實際上問。 –
你從哪裏得到的'$ _GET [「SelectedId」]'? – Swellar
'$ Carrier'將永遠不會有一個價值,因爲'$ _GET [「SelectedId」]'似乎你的代碼是失蹤 – Swellar