php - MySQL query working fine but not printing the record -
i want search data doctor table. have 1 record in doctor table , searching record , want echo data not working.
my query working fine not coming if statement. code this
<?php if(isset($_post['search']) && !empty($_post['search'])) { $province_option = $_post['province']; echo $province_option; $city_option = $_post['city']; echo $city_option; $specilization_option = $_post['specilization']; echo $specilization_option; $query = "select * doctor doc_specilization = '$specilization_option' , doc_city = '$city_option' , doc_province = '$province_option' "; echo "</br>"; echo $query; $result = mysqli_query($connection,$query); $count = mysqli_num_rows($result); if($count>0) { echo "inside if"; while ($row = mysqli_fetch_array($result)) { echo $row['doc_fname']; echo $row['doc_lname']; } } else {?> <strong> </br> <?php echo "no record found";?></strong> <?php } } ?>
database connection:
<?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $message; $type= "doctor"; $connection = mysqli_connect($dbhost, $dbuser, $dbpass) or die("conection error"); if(! $connection ) { die('could not connect: ' . mysqli_error()); } $database = mysqli_select_db($connection,"medical_network"); if (!$database) { die("database selection failed: " . mysqli_error()); } ?>
look coding fine,
as should in comment not section not in solution cant post there,
your query rely on the data submit in form, if data submitting in form , data matches database record gonna return rows,
so enter record got in database form click submit, think gonna work fine,
the reason executing else part this, submitted data not match record got in database, thats why when echo $count shows zero,
hope understand trying say
else statement gonna run if query return 0 rows per code
thanks
Comments
Post a Comment