简体   繁体   中英

PHP search form not getting results

I have a database with the name Harry Butler in it under the columns first_name and last_name with this code :

<?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'];
}


?>

Which gets the form data from the previous page :

<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>

Yet when the results are submitted i get nothing any ideas?

change

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

to this:

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

$_POST is associative array,so i hope it helped

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM