2017-04-25 16 views
-3

這是我的整個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來更新特定行。

+0

不知道什麼'SelectionId =「‘$承運人’。」;「'是假設做,如果你想要的ID添加到?字符串,你需要添加一個php塊:''UpdateStudent.php?SelectionId = <?= $ Carrier?>「'(這是PHP 101)如果這不是問題,你需要澄清你的問題,因爲它是_very_不清楚你實際上問。 –

+0

你從哪裏得到的'$ _GET [「SelectedId」]'? – Swellar

+0

'$ Carrier'將永遠不會有一個價值,因爲'$ _GET [「SelectedId」]'似乎你的代碼是失蹤 – Swellar

回答

0

我認爲你的意思是這樣的:

<a href="UpdateStudent.php?SelectionId=<?php echo $Carrier ;?>"> 
    <img src="sawiro/EditImage.jpg" alt="Edit Student Image"/> 
</a> 
+0

尚未解決, –

+0

@MohamedAbdullahiSalah - 如果您需要更多幫助,您確實需要開始向我們提供更多信息。 _「尚未解決」_是什麼意思?任何錯誤消息?怎麼了?預期的結果是什麼?這種解決方案不起作用嗎?還是其他的東西? –

+0

@MagnusEriksson - 您的治療結果是太長,張貼在這裏,順便說一下,我想收集目標PHP的ID中使用另一個PHP來更新特定行。 –

相關問題