PHP搜索表单没有得到结果

时间:2013-08-14 21:35:25

标签: php mysql

我有一个名为Harry Butler的数据库,其中包含first_name和last_name,其中包含以下代码:

<?PHP

//Create the connection…
//("where the database is", 'Database login' , 'database password' , "Database name")
$con=mysqli_connect("", 'root', 'root', "Social");

//Check our connection…
if (mysqli_connect_errno($con))
{
    echo " Sorry Mate";
}
$fname = $_POST[fname];
$lname = $_POST[lname];


$result = mysqli_query($con, "SELECT * FROM `User_info` WHERE first_name = '$fname' AND last_name = '$lname'");
while($row = mysqli_fetch_array($result))
{
echo $row['first_name'];
}


?>

从上一页获取表单数据:

<form action="searching.php" method="post">
<input id="fname" align="center" placeholder="First Name" name="fname"></input> 
<input id="lname" align="center" placeholder="Last Name" name="lname"></input>
    <select id="gender">
        <option value="Male">Male</option>
    <option value="Female">Female</option>
    <option value="Other">Other</option>
    <option value="God">God</option>
    </select>
    <br />
</form>

然而,当提交结果时,我什么都没有得到任何想法?

1 个答案:

答案 0 :(得分:1)

变化

$fname = $_POST[fname];
$lname = $_POST[lname];

到此:

$fname = $_POST['fname'];
$lname = $_POST['lname'];

$ _ POST是关联数组,所以我希望它有所帮助