无法将$ _POST(单选按钮)发送到另一个文件

时间:2013-12-19 15:16:30

标签: php mysqli

我制作一个显示卡片类型的文件供用户选择

<?php
include("connect.inc");
$connect=mysqli_connect($host,$username,$password,$dbname) or ("can't connect to server");
echo "<h2>Choose your card type </h2>";
$query="SELECT DISTINCT type FROM dragon";
$result=mysqli_query($connect,$query) or die("can't execute query");
$counter=1;
echo "<form action='ShowCardType.php' method='POST'>";
while($row=mysqli_fetch_assoc($result))
{
    extract($row);
    echo " <input type='radio' name='CardType' value='$type'";
    if($counter==1)
    {
        echo "checked='checked'";   
    }
    echo ">$type<br/>";
    $counter++;
}
echo "<input type='submit' value='select'>";
echo "</form>";
?>

第二个是文件显示用户选择的卡片。

<?php
include("connect.inc");
$connect=mysqli_connect($host,$username,$password,$dbname) or ("can't connect to server");
$type=$_POST['CardType'];
$query="SELECT * FROM dragon WHERE type='$type'";
$result=mysqli_query($connect,$query) or die("can't execute query");
while($row=mysqli_fetch_assoc($result))
{
    extract($row);
    echo $type."<br/>";
    echo $DragonID."/";
    echo $type;
    echo $DragonName."<br/>";
    echo $Description;
    echo "<br/>";
    echo "<a href='../dragon/{$picture}' border='0'> <img src='../dragon/{$picture}' border='0' width='300' height='300'/></a>";
}
?

&GT; 但是,当第二个文件运行时,它总是输出Notice: Undefined index: CardType in C:\xampp\htdocs\test\dragon-catalog\ShowCardType.php on line 4的通知 我想我对第一个文件做错了,但我不知道错误在哪里。

2 个答案:

答案 0 :(得分:1)

删除无线电输入的value='$type',因为它已命名为

并且您在第二个文件$type=$_POST['CardType'];

中声明了它

答案 1 :(得分:0)

请勿使用extract !!!

您的摘录会覆盖您的变量。

而是使用$row['type'] ......等等。