I know that I'm using multiple PHP styles, but I don't know how can I set this.
I think that there something wrong in exit()
; and I don't know what to do to get the desired result.
<?php
$mysqli = new mysqli("localhost", "root", "", "search");
if(isset($_GET['search_button']))
{
$search = $_GET['search'];
if(search=="")
{
echo "<center> <b> Please write something in Search Box </b> </center>"
exit();
}
$sql = "select * from website where site_key like '%$search%' limit 0, 5";
$rs = mysql_query($sql);
if(mysql_num_rows($rs)<1)
{
echo "<center> <h4> <b> Oops !!! Sorry, there is no result found to related the word. </b> </h4> </center>";
exit();
}
echo "<font size='+1' color='#1a1aff'> images for $search</font>";
while($row = mysql_fetch_array($rs))
{
echo "<td>
<table style='margin-top: 10px'>
<tr>
<td>
<img src='img/$row[5]' height='100px'>
</td>
</tr>
</table>
</td>"
}
}
?>
mysql_query($sql)
should be mysqli_query($mysqli,$sql)
mysql_num_rows($rs)
should be mysqli_num_rows($rs)
mysql_fetch_array($rs)
should be mysqli_fetch_array($rs)
You are mixing mysql
and mysqli
functions through one DB connection, which is wrong. You can mix mysql and mysqli but, need to have different DB connection. Read Getting a PHP PDO connection from a mysql_connect()?
Since, only one DB connection made and that is connected through mysqli. So,through out the application you have to use mysqli db connection variable for using mysqli functions.
Updated Code
<?php
$mysqli = new mysqli("localhost", "root", "", "search");
if (isset($_GET['search_button'])) {
$search = $_GET['search'];
if ($search == "") {
echo "<center> <b> Please write something in Search Box </b> </center>";
exit();
}
$sql = "select * from website where site_key like '%$search%' limit 0, 5";
$rs = mysqli_query($mysqli, $sql);
if (mysqli_num_rows($rs) < 1) {
echo "<center> <h4> <b> Oops !!! Sorry, there is no result found to related the word. </b> </h4> </center>";
exit();
}
echo "<font size='+1' color='#1a1aff'> images for $search</font>";
while ($row = mysqli_fetch_array($rs)) {
echo "<td>
<table style='margin-top: 10px'>
<tr>
<td>
<img src='img/$row[5]' height='100px'>
</td>
</tr>
</table>
</td>";
}
}