Php 使用GET函数时通过MySQL数据库未定义索引
我在这儿。我已经写了8个步骤,试图从数据库中获取数据,但我的第一行只返回了 “注意:中未定义的索引:itemid” C:\xampp\htdocs\1605267B\KUSO\cart.php,第130行“ 在第一行使用GET函数,我没有发现任何错误。请帮帮我Php 使用GET函数时通过MySQL数据库未定义索引,php,mysql,Php,Mysql,我在这儿。我已经写了8个步骤,试图从数据库中获取数据,但我的第一行只返回了 “注意:中未定义的索引:itemid” C:\xampp\htdocs\1605267B\KUSO\cart.php,第130行“ 在第一行使用GET函数,我没有发现任何错误。请帮帮我 <?php $itemid = $_GET['itemid']; //TODO 1: Connect to forumdb database $mysqli = new mysqli("localhost","root",nul
<?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();
?>
更改以下行
$itemid = $_GET['itemid'];
与
如果您不想显示任何匹配项,则0应为任何默认id或0。那么您是否使用查询字符串发送itemid?例如:example.com?itemid=1@GurV它仍然不能正常工作,仍然返回相同的东西(这里没有问题。因此,您确认您的查询如下:www.example.com?itemid=12 Try like@OmarFaruque said的可能重复项。将id 1更改为您找到的任何其他id。)
$itemid = !empty($_GET['itemid']) ? $_GET['itemid'] : 0;