I am trying to learn "searching elements from mysql database using php".
For this I created a database named randomdata. In randomdata database there is a table named randomtable. In this table there are four columns: Name, Surname, Email and Gender.
I want to search people by there Gender. For this I tried following query.
$query="SELECT * FROM randomtable WHERE Gender =' ".$gender . " ' ";
I tried both, GET and POST functions. But still I am not able to take output. I am using these.
- Windows 8
- Wampserver
Notepad++
I restarted server and PC, but nothing changed. Below is my complete code.
Find Entries:
Male
Female
<?php if(isset($_POST['submit'])) { echo $gender=$_POST['$gender']; $connect=mysql_connect("127.0.0.1","root","", "randomdata"); if($connect) { //echo 'I am connected'; $query="SELECT * FROM randomtable WHERE Gender =' ".$gender . " ' "; echo $query; $results=mysqli_query( $connect,$query); while($row = mysqli_fetch_array($results)) { echo $row['Name'] . "<br/>" . $row['Surname'] . "<br/>" . $row['Email'] . "<br/>" ; } } else { die(mysql_error()); } } ?>
$_POST['$gender']to$_POST['gender']? Shooting in the dark. Maybe your$genderparam is empty.$genderinside thePOST['$gender']gender you getting form through POST method is not a php variable