Basically I have tried creating another search function that will search the VAT registration number "vat_registration_number" from my "vat" table and I have stumbled across another problem yet again. I have created this code for this search below.
<form name="search" action=<?php Print $_SERVER["PHP_SELF"]; ?> method="post">
<br>
<hr width=100%>
<?php
$Order = (isset($_POST['Order']))?$_POST['Order']:"tax_id";
$InOrder = (isset($_POST['InOrder']))?$_POST['InOrder']:"";
$vatreg = (isset($_POST['vatreg']))?$_POST['vatreg']:"";
?>
<strong><br>
</strong>
<table align=center>
<th align=center><span class="style7">Search For VAT Registration Number: </span>
<td><input type ="text" name="vatreg" value ="<?print $vatreg;?>"size="40">
</table>
<br>
<table align=center>
<td> <span class="style13">Make Search Found Ascending Or Descending:</span>
<select name="InOrder">
<option value="ASC"<?if ($InOrder == "ASC"){print ' SELECTED ';}?>>Ascending</option>
<option value="DESC"<?if ($InOrder == "DESC"){print ' SELECTED ';}?>>Descending</option>
</select>
</table>
<br>
<table align=center>
<th align=center>
<td><input type="submit" name="submit" value="Search" />
</table>
<br>
<hr width=100%>
<?
//May not be needed depending on the connection.
$conn = mysql_connect("localhost","root","") or die("Could Not Connect To The Database");
mysql_select_db("aziz",$conn) or die("Could Not Select The Database");
//build up query using each conditional - else statement refers to search field.
$conditional = "";
if ($vatreg ==""){
$conditional=$conditional."vat_registration_number = '".$vatreg."'";
}
$conditional="WHERE ".substr($conditional,0,strlen($conditional)-4);
$query = "SELECT vat_id, c_registration_no, vat_registration_number, vat_effective_date, vat_quarter FROM vat WHERE vat_registration_number = '$vatreg' ORDER BY $Order $InOrder";
$search = mysql_query($query,$conn);
$NumRows=mysql_num_rows($search);
?>
<center>
<b></strong><?print "There are $NumRows found items related to your search ";?></b>
<span class="style3"><span class="style3 style5"></span></span>
</center>
<br>
<table border="0" cellpadding="0" cellspacing="0" align="center">
<tr height="20">
<td bgcolor="#93B0B4" width="145"><span class="style4 style13">VAT ID </span></td>
<td bgcolor="#93B0B4" width="145"><span class="style4 style13">Company Registration Number</span></td>
<td bgcolor="#93B0B4" width="145"><span class="style4 style13">VAT Registration Number</span></td>
<td bgcolor="#93B0B4" width="145"><span class="style4 style13">VAT Effective Date (YYYY-MM-DD)</span></td>
<td bgcolor="#93B0B4" width="145"><span class="style4 style13">VAT Quarter</span></td>
<td bgcolor="#93B0B4" width="125"><span class="style4 style13">Delete Client</span></td>
</tr>
<tr>
<td>
<?php
if($NumRows>0){
//get the first row and begin the table.
$row = mysql_fetch_assoc ($search);
//reset the result set back to the first row and display the data set.
mysql_data_seek ($search, 0);
while ($row = mysql_fetch_row ($search)) {
echo "<tr valign=top>";
echo "<td bgcolor=#93B0B4 colspan=6></td>";
echo "</tr>";
print "<TR>\n";
print "<TD>$row[0]</TD>";
print "<TD>$row[1]</TD>";
print "<TD>$row[2]</TD>";
print "<TD>$row[3]</TD>";
print "<TD>$row[4]</TD>";
if($row[2]=="vatreg"){
?>
</td>
</tr>
</table>
<?php
print $row[0];
?>
<?php
print "</TR>";
}
else{
?>
</form>
</blockquote>
<td><a href ="viewvat2.php?id=
<?php
print $row[0];
?>
">View</a></td>
<?php
print "</tr>";
}
}
print "</table>";
}
?>
When I run this it comes up with this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\apachefriends\xampp\htdocs\searchvatreg.php on line 183
which line 183 is this part of the code:
$NumRows=mysql_num_rows($search);
which is connected to this part of the code:
$conditional = "";
if ($vatreg ==""){
$conditional=$conditional."vat_registration_number = '".$vatreg."'";
}
$conditional="WHERE ".substr($conditional,0,strlen($conditional)-4);
$query = "SELECT vat_id, c_registration_no, vat_registration_number, vat_effective_date, vat_quarter FROM vat WHERE vat_registration_number = '$vatreg' ORDER BY $Order $InOrder";
$search = mysql_query($query,$conn);
$NumRows=mysql_num_rows($search);
It maybe something small I'm missing I have tried so many different ways in solving this problem but nothing has worked so far. I hope someone can help me to figure out a solution to help me solve this problem because I have tried everything I can do with my basic knowledge of PHP.
I really hope someone can help me with this problem I would be really greatfull
Thankyou for your time
Take Care