Problems with validating data for a search
Posted: Tue Sep 12, 2006 8:18 am
feyd | Please use
What' s wrong with it?
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I want to build a search page for the website I' m working on and I having some trouble with the validation.
Here is the scenario for this page:
1. user enters the page
2. completes or doesn't the search field
3 a. in case of errors (the field is empty or it is too short) error messages appear
b. if the word he search for doesn' t exist in t he database an error message appears
4. the search results appear
But it doesn' t work at all: no error messages, no results.
Here is the code:Code: Select all
<?php
//inclusion of the other php functions i need
//declaration of the variables $term= the search term, $valid= the indicator that the validation is finished
$term='';
$valid=false;
//conection to the database
//first search function in the MySQL
function select_cat($p='')
{
$int=''";
//array in which will be put the result of the query
$q='';
$rez='';
//the query
$int="SELECT...'";
$q=mysql_query($int) or die(mysql_error());
echo "<tr><td>\t<h2> Results</h2></td></tr>\r\n";
while($rez=mysql_fetch_array($q))
{
if (count($q)==0) { return false;}
else
{
return true;
return true;
echo "\t\t <tr>\r";
echo "\t\t\t <td colspan=3>" ."<a href='url?subcat=" .$r2['Sc'] ."'>" .$r2['NumeSub'] ."</a>" ."</td>\r";
echo "\t\t</tr>\r";
}
}
}
?>
<form method='POST' action=' <?php echo $_SERVER['PHP_SELF'] ?> '>
<table>
<tr>
<td>Introduceti termenul pe care- l cautati.<td>
<td><input type='text' name='termen'></td>
<td><input type='submit' value='Cauta'></td>
</tr>
<?php
$term=$_POST["termen"];
/* if(isset($_POST["submit"]) && $valid==false)
{
if(trim($termen)=='') {echo "Message 1"; $valid=false; }
else if(strlen(trim($termen))<3){echo "Message 2"; $valid=false;}
else {$valid=true;}
}
if ($valid==true)
{
$term=addslashes($_POST['termen']);
if ((select_pr$term)==false)&&(select_cat($term)==false))
{
echo "<h2>Ne pare rau dar nu avem termenul cautat in baza de date</h2>";
}
}*/
</table>
</form>
Sf();
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]