If i had a search input not account/password input, do i need to use mysql_real_escape_string?
could be sql injection?? $sql just select where limit row
<input type="text" name="search">
include"set.php";
$search=$_POST["search"];
if(strlen($search)) >= $min_length){
$sql="select * from $tbl where subject or content like '%search%';";
..
}
(mysql: subject and content both ‘text’ type)
if i need to use, i try this but doesnt work.
include"set.php";
$search=mysql_real_escape_string($_POST["search"]);
if(strlen($search)) >= $min_length){
$sql="select * from $tbl where subject or content like '%search%';";
..
if(mysql_num_rows($query)>0){
while ($list= mysql_fetch_array($query)){
$subject=$list[subject];
$content=$list[content];
$...=$list[...];
print "subject: $subject, ....";
}
}
else{
print "no results";
}
}
else{
print "minimum length is". $min_length;
}
A. It should be
$_POSTnot$_postvariable name are case sensitive in PHPB.
mysql_**Depreciated use mysqli_real_escape_string insteadFROM PHP DOC
C. Its always better to design a search form with
$_GETinstead so that the URL can easily be savedExample
D. You would never trust user input and aways validate and filter all the time