<?php
include("connect.php"); 
$cat_id=$_REQUEST['cat_id'];
$search_key=$_REQUEST['search_key'];
if($search_key != "")
{ 
$sql=mysql_query("SELECT * FROM tbl_products WHERE title LIKE '%$search_key%' OR short_descrp LIKE '%$search_key%' OR description LIKE '%$search_key%'")or die(mysql_error());
$count=mysql_num_rows($sql);
if($count > 0)
{
while($row_city=mysql_fetch_array($sql))
    {
    //echo $row_city['title']."<br>";
    //echo $row_city['short_descrp'];
    ?>    
 <div class="section group">
<div class="city">
<div style="float:left">
    <img src="images/member_posts/<?=$row_city['image1'];?>" title="<?=$row_city['title'];?>"  height="100" width="160" >
</div>
<div style="float:none">
<p><?=$row_city['title'];?></p>
<h1>Rs : <?=$row_city['amount']?></h1>
<p>Negotiable Status&nbsp;:&nbsp;<?=$row_city['negotiable'];?></p>
<a href="product.php?pro_id=<?=$row_city['id']?>&& cat_id=<?=$cat_id?>" class="link">Read More</a>
</div>
</div>
</div>

   <?php
    }
    }
else
?>
<?php
{
echo '<script type="text/javascript">alert("Keyword Does not match");window.location.href="category.php";</script>';
}
}
else
{
?>
<?php
echo '<script type="text/javascript">alert("Please Type to Search");window.location.href="category.php";</script>';
}
mysql_close($con);
?>


in this code, for me, alert box is not working????? what is the problem??? in my code...

ONclick only working , If i give on submit instead onsubmit its not working....
Tell me where I have error, and What I have to change?

Recommended Answers

All 3 Replies

For starters, why do you close PHP then open it again right after closing it?

?>
<?php
Member Avatar for diafol

As stated before in some previous threads:

1) Use POST or GET not REQUEST
2) Stop using mysql_* - use mysqli or PDO
3) Separate your PHP and HTML
4) Leave HTML as HTML - no point getting PHP to echo out static markup.

using your code i tidied it up a bit the alert box is working.

<?php
    include("connect.php"); 
    $cat_id=$_REQUEST['cat_id'];
    $search_key=$_REQUEST['search_key'];
    if($search_key != ""){ 
            $sql=mysql_query("SELECT * FROM tbl_products WHERE title LIKE '%$search_key%' OR short_descrp LIKE '%$search_key%' OR description LIKE '%$search_key%'")or die(mysql_error());
            $count=mysql_num_rows($sql);
            if($count > 0){
                        while($row_city=mysql_fetch_array($sql))
                        {
                            ?>    
                            <div class="section group">
                            <div class="city">
                            <div style="float:left">
                            <img src="images/member_posts/<?=$row_city['image1'];?>" title="<?=$row_city['title'];?>"  height="100" width="160" >
                            </div>
                            <div style="float:none">
                            <p><?=$row_city['title'];?></p>
                            <h1>Rs : <?=$row_city['amount']?></h1>
                            <p>Negotiable Status : <?=$row_city['negotiable'];?></p>
                            <a href="product.php?pro_id=<?=$row_city['id']?>&& cat_id=<?=$cat_id?>" class="link">Read More</a>
                            </div>
                            </div>
                            </div>
                            <?php
                        }
            }
            else{
            echo '<script type="text/javascript">alert("Keyword Does not match");window.location.href="category.php";</script>';
            }
    }
    else{
            echo '<script type="text/javascript">alert("Please Type to Search");window.location.href="category.php";</script>';
    }

    mysql_close($con);
    ?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.