我使用这种形式的 add.php
echo " <td><form action='view_ticket.php' method='get'>
<input type='hidden' id='itemid' name='itemid' value='". $row["id"] ."'/>
<input type='submit' value='Buy' class='btn-link'/>
</form></td>";
echo "</tr>";
我知道了 view_ticket.php
<?php
session_start();
$conn = mysqli_connect("localhost", "localhost", "localhost",
"localhost");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$id = $_GET['itemid'];
$sql = "SELECT id,username FROM tickets WHERE id = '" . $id . "'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if ($row['username'] = $_SESSION['username']) {
}
else
{
header("location:/quickshops/buyer/tickets.php");
}
}
}
?>
我猜唯一的问题是$ id = $ _GET ['itemid'];出空idk如何 我检查了add.php的源代码,隐藏区域中的id是真实的,真实的和数字
答案 0 :(得分:0)
在每个步骤输出$ _GET,例如查看在哪里松动
echo 'About to look for id "' . htmlspecialchars($id) . '"<br>';
$result = $conn->query($sql);
echo 'Just executed SQL query<br>';
var_dump($_GET); echo '<br>';
if ($result === false) {
echo 'SQL Query Error!<br>';
var_dump($_GET); echo '<br>';
} else if ($result->num_rows > 0) {
echo $result->num_rows . ' row(s) found<br>';
var_dump($_GET); echo '<br>'; /* do something */
} else {
echo 'No rows round<br>';
var_dump($_GET); echo '<br>';
}