I am using the code below for search function but it is not protected from injections and I am not programming expert so can anyone help me on this my code is
just want to add code that can protect from injections.
Code:
<?php include ( "./inc/header.inc.php" ); ?> <?php if(!isset($_POST['search'])) { header("Location: main.php"); } $search_sql="SELECT * FROM blogs WHERE title LIKE '%".$_POST['search']."%' OR body LIKE '%".$_POST['search']."%' "; $search_query=mysql_query($search_sql); if(mysql_num_rows($search_query) !=0){ $search_rs=mysql_fetch_assoc($search_query); } ?> <p>Search results</p> <?php if(mysql_num_rows($search_query) !=0){ do { ?> <div class="searchresults"> <p><?php echo $search_rs['title']; ?></p> <p><?php echo $search_rs['body']; ?></p></div> <?php } while ($search_rs=mysql_fetch_assoc($search_query)); } else { echo "No results found"; } ?>
Comment