Hi everyone!, I need your help. I got an error in code, my compiler said "mysq_query() experts parameter 1 to be string, resource given test.php line 21" and "mysql_fetch_array() expects parameter 1 to be resource, null given in test.php on line 72" and I can't figure out how to solve this errors and I don't know how I will add pagination on my codes and I would like to know how I can show any message when there is no result from the filters. . Please see and check my codes below. Thank you in advance for your help. :)
Here is my codes:
<?php
if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
$query = "SELECT * FROM `dbcharity2016` WHERE CONCAT(`genNo`, `reliefNo`, `disas_date`, `area`, `city`, `type`, `surv_date`, `surv_date`, `surv_volunteers`, `vol_incharge`, `relief_date`, `volunteers`, `venue`, `T_Beneficiary`, `unit`, `individual`, `house`, `sacksNo`, `DRG`, `cost_set`, `cost_relief`, `DAI`, `CAG`, `TCA`) LIKE '%".$valueToSearch."%'";
$search_result = filterTable($query);
}
else {
$query = "SELECT * FROM `dbcharity2016`";
$search_result = filterTable($query);
}
function filterTable($query)
{
$con = mysql_connect("localhost","test_webdev","e7#_AZ*9we_^","test_WebBase");
$filter_Result = mysql_query($con, $query);
return $filter_Result;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<style>
table,tr,th,td
{
border: 1px solid black;
}
</style>
</head>
<body>
<form action="test.php" method="post">
<input type="text" name="valueToSearch" placeholder="Value To Search"><br><br>
<input type="submit" name="search" value="Filter"><br><br>
<table>
<tr>
<th>General No.</th>
<th>Relief No.</th>
<th>Disaster Date</th>
<th>Area</th>
<th>City</th>
<th>Relief type</th>
<th>Survey Date</th>
<th>Survey Volunteers</th>
<th>Volunteer-in-Charge</th>
<th>Relief Date</th>
<th>Volunteers</th>
<th>Venue</th>
<th>Beneficiary</th>
<th>Unit</th>
<th>Individual</th>
<th>House</th>
<th>No. of Sacks</th>
<th>Details of Relief Goods</th>
<th>Cost per set</th>
<th>Cost of Relief Goods
<th>Death and Injuries</th>
<th>Cash Assistance</th>
<th>Total Cash Assistance</th>
</tr>
<!-- populate table from mysql database -->
<?php while($row = mysql_fetch_array($search_result)):?>
<tr>
<td><?php echo $row['genNo'];?></td>
<td><?php echo $row['reliefNo'];?></td>
<td><?php echo $row['disas_date'];?></td>
<td><?php echo $row['area'];?></td>
<td><?php echo $row['city'];?></td>
<td><?php echo $row['type'];?></td>
<td><?php echo $row['surv_date'];?></td>
<td><?php echo $row['surv_volunteers'];?></td>
<td><?php echo $row['vol_incharge'];?></td>
<td><?php echo $row['relief_date'];?></td>
<td><?php echo $row['volunteers'];?></td>
<td><?php echo $row['venue'];?></td>
<td><?php echo $row['T_Beneficiary'];?></td>
<td><?php echo $row['unit'];?></td>
<td><?php echo $row['individual'];?></td>
<td><?php echo $row['house'];?></td>
<td><?php echo $row ['sacksNo'];?></td>
<td><?php echo $row ['DRG'];?></td>
<td><?php echo $row ['cost_set'];?></td>
<td><?php echo $row ['cost_relief'];?></td>
<td><?php echo $row ['DAI'];?></td>
<td><?php echo $row ['CAG'];?></td>
<td><?php echo $row ['TCA'];?></td>
</tr>
<?php endwhile;?>
</table>
</form>
</body>
</html>
What I have tried:
I tried to change $connection to $con and mysqli_query to mysql_query, unfortunately the error is still there and increased more. I don't know how I fix this mess and how I add pagination too in every page when table hit 10 rows automatic the pagination will appeared. and I know too how to show message "No Result" when there is no result in filter.
[edit by Nelek] Additional information copied from non answer below
And I'm using php version 4.0.1 and Mysql version 5.5.54