Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Feb 21st, 2006, 6:04 AM   #1
guess
Programmer
 
Join Date: Feb 2006
Posts: 40
Rep Power: 0 guess is on a distinguished road
A complicated php,form,mysql

in search.php,I have 5 fields and I am passing those variables by get method to the search2.php. I want search2.php to perform a database search according to the information entered by the user and print the result to the search2.php. Everything is ok.Queries,tables.However,I need to be guided about how am I going to search the database with only one key.If I had known which fields are empty and which fields are not,I would write the query according to this.I tried to use isset function for that,however it is always returning true because Im getting them by the post method just like this ;
$ilk = @$_POST["ilktarih"];

So I think it is always returning true because it is initialized at the beginning of the search2.php although I user doesnt enter anything to the fields.

One more thing,Even if I could use the isset function efficiently, there are 5 fields and there are lots of combinations of filling those fields(ex:filling just one,filling the one at the top and the bottom,filling them all).It takes lots of time to write if checks and write the query again and again according to the if checks.Im asking this because I dont know how these kind of searches are coded.

If anybody helps me how to run a query with only one button and make the database bring me the information,I would be grateful.

SEARCH.PHP

<body>
<form name="send" method="post" action="search2.php">
<a style="size:auto ">Baslangiç tarihi : </a> &nbsp; <input type="text" name="ilktarih" size="30" ><br><br>
<a style="size:auto ">Bitis tarihi : </a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="sontarih" size="30" ><br><br>
<a style="size:auto ">From : </a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="from" size="30" ><br><br>
<a style="size:auto ">To : </a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="to" size="30" ><br><br>
<a style="size:auto ">From : </a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<select name="spamlist">
<option value="UNSAFE">UNSAFE
<option value="SAFE">SAFE
<option value="BODY">BODY
<option value="ATTACH">ATTACH
<option value="VIRUS">VIRUS
<option value="EMPTY">EMPTY
<option value="ERROR">ERROR
</select><br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit" value="SEARCH">
</form>


SEARCH2.PHP

<body>
<?
$ilk = @$_POST["ilktarih"];
$son = @$_POST["sontarih"];
$from = @$_POST["from"];
$to = @$_POST["to"];
$spam = @$_POST["spamlist"];

/*$a=array($ilk,$son,$from,$to);
for($i=0;$i<5;$i++)
{
if(isset($a[$i])){
$set[$i]=true;
echo $set[$i];
}
}*/
$dbhost = '127.0.0.1';
$dbuser = 'root';
$dbpass = '05364304334';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$dbname = 'kutay';
mysql_select_db($dbname);

$query ="select * from t1";
if(empty($ilk) && empty($son) && empty($from) && empty($to)){
$query = $query . " where stats=' $spam'";
}
$result=mysql_query($query,$conn) or die('Error: '.mysql_error().' -- Query: '.$query);

echo "<table border=1>\n";



echo "<tr><td>Rowcount</td><td>Date</td><td>Time</td><td>Status</td><td>Queue</td><td>Recvfrom</td><td>From</td><td>To</td><td>Subject</td><td>Spam</td><td>Rule</td></tr>\n";


$count=1;
while ($myrow = mysql_fetch_row($result)) {



printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",
$count, $myrow[1], $myrow[2], $myrow[3], $myrow[4], $myrow[5], $myrow[6], $myrow[7], $myrow[8], $myrow[9], $myrow[10]);
$count++;
}
echo "</table>\n";
?>
guess is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:58 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC