how to display the mobile no in mobile no label searching by employee id in html using php and mysql -
i want display mobile number in mobileno label when enter employee id search code displays no result.
i want display data using while loop in html form
search.php
<?php $output = null; $mysqli = mysqli_connect("localhost","root","","db") or die ("error in connection"); if(isset($_post['search'])) { $search = $mysqli->real_escape_string(isset($_post['search'])); $resultset = $mysqli->query("select * emp emp_id = '$search'"); if($resultset->num_rows > 0) { while($rows = mysqli_fetch_row($resultset)) { $mobileno = $rows['emp_mob_no']; $output = "mobile no: $mobileno"; } } { $output = "no result"; } } ?>
display.php
<html> <head> </head> <body> <form action="search.php" method="post"> <ul> <li> <label for="employeeid">employee id</label> <input type="text" name="employeeid" placeholder="employee id" /> <input type="submit" value="search" name="search"/> </li> <li> <label for="mobileno">mobile no.</label> <?php echo $output;?> </li> </form> </body> </html>
1st : missed else
that's why $output variable alwasy overwrite no result .
2nd : $search = $mysqli->real_escape_string(isset($_post['search']));
line wrong isset return boolean value escaping boolean value .
3rd : try use prepared statement avoid sql injection .
php:
<?php $output = null; $mysqli = mysqli_connect("localhost","root","","db") or die ("error in connection"); if(isset($_post['search'])) { $search=$_post['search']; $stmt = $conn->prepare("select * emp emp_id = ?"); $stmt->bind_param('i',$_post['search']); $stmt->execute(); $get_result = $stmt->get_result(); if($get_result->num_rows > 0) { while($rows = $get_result->fetch_assoc()) { $mobileno = $rows['emp_mob_no']; $output = "mobile no: $mobileno"; } }else //here else missed . { $output = "no result"; } } ?>
Comments
Post a Comment