Undefined index errors accessing $_POST

2019-07-18 03:23发布

I keep trying to fix this but it's giving me the same errors:

Notice: Undefined index: items in C:\xampp\htdocs\shop.php on line 9

Notice: Undefined index: body in C:\xampp\htdocs\shop.php on line 24

Here is my code:

<form action="" method="post">
    <input type="radio" name="items" value="fed" /> Fed<br />
    <input type="radio" name="items" value="body" /> Body<Br>
    <input type="submit" name="submit"><br>
</form> 

<?php
if(isset($_POST['submit'])) {
     $items = $_POST['items'];
     if($items=="fed") {
         echo "You choose feds";    
         die();
     }
     else
         echo "<Form action='' method='POST'>
         <select name='body'>
         <option value='head'>Head</option>
         </select>
         <input type='submit' name='submit' value='submit' /><br />
         </form>";

 if(isset($_POST['submit'])) {
    $body = $_POST['body'];
    $connect = mysql_connect("localhost","root","")or die(mysql_error());
    mysql_select_db("feds",$connect)or die(mysql_error());

    $merchandise = mysql_query("SELECT * FROM merchandise WHERE body_part='$body' ")or     die(mysql_error());

    while($row = mysql_fetch_array($merchandise)) {
        echo $row['item'];  
        echo "<bR>";
    }
}


} 
?>

标签: php html forms
7条回答
混吃等死
2楼-- · 2019-07-18 04:04

Hey just use method as "POST" instead of "post" .hope so it would solve your problem just like mine.

Happy coding

查看更多
登录 后发表回答