我有問題的示例頁,將檢索URL'update.php?id = 1'的學生ID使用它在查詢中,當我在查詢它的工作手動編寫ID ..不能想出GET和POST在PDO
update.php
<?php
require 'database.php';
$id=$_GET['id'];
if (!empty($_POST)) {
$name=$_POST['name'];
$mobile=$_POST['mobile'];
$pdo=Database::connect();
$sql="UPDATE students SET name=? , mobile=? WHERE id=?";
$q=$pdo->prepare($sql);
$q->execute(array($name,$mobile,$id));
Database::disconnect();
header('Location: index.php');
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div>
<div>
<div>
<h3>Update Student Information</h3>
</div>
<form action="update.php" method="post">
<div>
<label>Name</label>
<div>
<input name="name" type="text">
</div>
</div>
<div>
<label>Mobile No.</label>
<div>
<input name="mobile" type="text">
</div>
</div>
<div>
<button type="submit">Add</button>
<a href="index.php">Back</a>
</div>
</form>
</div>
</div>
</body>
</html>
UPDATE:爲了更清楚的ID從其他頁面的URL地址檢索就像我從HTML表單...網址「update.php說不?id = 1'我應該怎麼做?
的index.php
<?php
include 'database.php';
$pdo = Database::connect();
$sql = 'SELECT * FROM students';
foreach ($pdo->query($sql) as $row) {
echo '<tr>';
echo '<td>'. $row['name'] . '</td>';
echo '<td>'. $row['mobile'] . '</td>';
echo '<td><a href="show.php?id='. $row['id'].'">Show</a></td>';
echo '<td><a href="update.php?id='. $row['id'].">Update</a></td>';
echo '</tr>';
}
Database::disconnect();
?>
你使用'$ ID = $ _ GET [ '身份證']檢索;''GET'但你的表格是'POST'? – Rizier123 2014-12-13 10:11:23
爲了清楚這個id從其他頁面的URL地址檢索像我說的不是從HTML表單... url'update.php?id = 1'我應該怎麼做? – Bionz 2014-12-13 10:54:51