I'm currently trying to get into php
and MySQL
and i'm using this little project as a learning curve, but I've hit a bump that I can't get through. I have the following code that is accessing my MySQL database and I am currently trying to echo the data out using the following search function:
<?php
ob_start();
require("config.php");
ob_end_clean();
$req=$_REQUEST['workingDate'];
$req2=$_REQUEST['location'];
mysql_connect("XXXXXXXXXXX",$username,$password);
mysql_select_db($database) or die( "Unable to select database");
if ($req!="all" && $req2!="all") $query="SELECT * FROM TrackerTable WHERE workingDate='$req' AND location1='$req2'";
else if($req=="all" && $req2!="all" ) $query="SELECT * FROM TrackerTable WHERE location1='$req2'";
else if($req!="all" && $req2=="all" ) $query="SELECT * FROM TrackerTable WHERE make='$req'";
else if($req=="all" || $req2=="all" ) $query="SELECT * FROM TrackerTable";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_query($result);
mysql_close();
$i=0;
for ($i; $i < $num; $i++){
$f12=mysql_result($result,$i,"workingDate");
$f13=mysql_result($result,$i,"location1");
echo $f12." ".$f13."<br />";
}
?>
The problem I have is that whenever I try to search the database using the following html form:
<form method="post" action="searchFunction.php" name="input" id="searchform">
<label class="section">Search Options</label><br />
<input name="workingDate" type="text" id="workingDate" placeholder="Search by Date">
<input name="location1" type="text" id="location1" placeholder="Search by Location">
<input name="submit" type="submit" id="add" value="Find!">
</form>
I get this error thrown at me:
Warning: mysql_query() expects parameter 1 to be string, resource given in /XXXXXX/XXXXXX/XXXXX/XXXX/XXXXX.com/XXXXXX/searchFunction.php on line 20
I have no idea what could be causing the problem as it all seems fairly in place to me. Is there an obvious mistake i'm making or is it all just completely messed up? I've been looking at it that long that I can't tell what makes sense anymore!
Any help would be greatly appreciated. Thanks guys!