PHP noob在这里。我已经写出了试图从数据库中获取数据的第8步,但我的第一行只是回复了
“注意:未定义的索引:itemid in 第130行的C:\ xampp \ htdocs \ 1605267B \ KUSO \ cart.php“
我在第一行使用GET功能时发现没有任何问题。请帮帮我。
<?php
$itemid = $_GET['itemid'];
//TODO 1: Connect to forumdb database
$mysqli = new mysqli("localhost","root",null,"kuso");
//TODO 2: Prepare the statement to select message id and subject info belonging to $userid from forummessage table
$stmt = $mysqli->prepare("select itemid, itemname, itempicture, description, price from items where itemid=?");
//TODO 3: Bind the values
$stmt->bind_param("i",$itemid);
//TODO 4: Execute the statement
$stmt->execute();
//TODO 5: bind results into $messageid, $subject
$stmt->bind_result($itemid, $itemname, $itempicture, $description, $price);
echo "<table border='1'>";
echo "<tr><td><b>Subject</b></td><td><b>Actions</b></td></tr>";
// Use while loop to fetch messages and put in a <table>
while ($stmt->fetch()) {
echo "<tr>";
//TODO 6: In 1st <td>, display subject
echo "Sliim-fit.jpg";
echo "<a href='menschoice.php?productid==$itemid'>";
//TODO 7: In 2nd <td>, display View hyperlink with messageid in query string.
//The View hyperlink links to messagedetails.php
echo "<td> <a href='messagedetails.php?messageid=$messageid'> View </a></td>";
echo "</tr>";
}
echo "</table>";
//TODO 8: close the statement
$stmt->close();
//TODO 9: close $mysqli
$mysqli->close();
?>
我不知道为什么它一直让我退回未定义的索引。帮助我感谢senpais。
答案 0 :(得分:0)
更改以下行
$itemid = $_GET['itemid'];
使用
$itemid = !empty($_GET['itemid']) ? $_GET['itemid'] : 0;
如果您不想显示任何匹配项,则零应为任何默认ID或0。