PHP-MYSQL help

This is where you share YOUR scripts with others

Moderators: macek, egami, gesf

mysterio864
New php-forum User
New php-forum User
Posts: 1
Joined: Sun Aug 21, 2011 7:20 pm

PHP-MYSQL help

Postby mysterio864 » Sun Aug 21, 2011 7:26 pm

Hello everyone!

I am having a hard time with this code and I hope that someone can help me:

<html>
<title>Search Application Form</title>
<head>
<link href="css.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="script.js"></script>
<base target="_self">
<?php
include "connect.php";
include "validatelogin2.php";
?>
</head>
<body id="body2">
<center>
<FORM method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
<table id="table2">
<tr><td width="50">Search:</td><td><INPUT type="text" name="searchstring" framewidth="4" size="20"></td></tr>
<tr><td width="50">Within:</td>
<td><select name="searchtype">
<option value="sname">School</option>
<option value="remarks">Remark</option>
<option value="lname">Last Name</option>
<option value="fname">First Name</option>
<option value="mobile">Mobile</option>
<option value="email">Email Adress</option>
<option value="id">ID #</option>
</select>
</td></tr>
</table>
<INPUT type="Reset" value="Clear"> <INPUT type="submit" value="Search" name="Submit">
</FORM>
</center>
<table id="table3" border=1 cellpadding=1 cellspacing=1 bordercolor="#000000" align="center">
<tr bgcolor='#9999FF'>
<td><center><font color="#ff0000"><b>#</b></font></center></td>
<td><center><font color="#ff0000"><b>Full Name</b></font></center></td>
<td><center><font color="#ff0000"><b>Academic Institution</b></font></center></td>
<td><center><font color="#ff0000"><b>Email</b></font></center></td>
<td><center><font color="#ff0000"><b>Mobile Number</b></font></center></td>
<td><center><font color="#ff0000"><b>Remarks</b></font></center></td>
<td><center><font color="#ff0000"><b>Date Added</b></font></center></td>
<td><center><font color="#ff0000"><b>Added By</b></font></center></td>
</tr>
<?php
if(isset($_POST['Submit'])){
$searchstring = $_POST['searchstring'];
$searchtype = $_POST['searchtype'];
if($searchstring == ""){
echo "<h3><center>Empty Search Box</h3>";
}else{
$sql=mysql_query("SELECT application.lname, application.fname, application.sname, application.email, application.mobile, remark.remarks, remark.dateadded, remark.addedby FROM application WHERE application.$searchtype LIKE 'application.%$searchstring%' LEFT JOIN remark ON 'application.id'='remark.id' ORDER BY remark.dateadded desc, application.sname, application.lname, application.fname;");
$i=1;
if(mysql_num_rows($sql) == "0"){
echo "<h3><center>Query not found.</h3></center>";
}else{
while ($row=mysql_fetch_array($sql)){
?>
<tr>
<td><?php echo $i; $i++; ?></td>
<td><a href="solo.php?id=<?php echo $row['id']; ?>"><?php echo $row['appplication.lname']; ?>, <?php echo $row['appplication.fname']; ?></a></td>
<td><?php echo $row['appplication.sname']; ?></td>
<td><a href="mailto:<?php echo $row['appplication.email']; ?>"><?php echo $row['appplication.email']; ?></a></td>
<td><?php echo $row['appplication.mobile']; ?></td>
<td><?php echo $row['remark.remarks']; ?></td>
<td><?php echo $row['remark.dateadded']; ?></td>
<td><?php echo $row['remark.addedby']; ?></td>
</tr>
<?php } } } } ?>
</table>
<br>
</center>
</body>
</html>

Because when I am trying to search within the database the following error occurs:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\hri\weusa\remarksearch2.php on line 52

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\hri\weusa\remarksearch2.php on line 55

please help..

lokanath7
New php-forum User
New php-forum User
Posts: 139
Joined: Mon Nov 15, 2010 12:11 am

Re: PHP-MYSQL help

Postby lokanath7 » Wed Aug 24, 2011 7:52 am

mysql_num_rows() returns integer...so change ur line

if(mysql_num_rows($sql) == "0")

to

if(mysql_num_rows($sql) == 0){


Return to “Your Scripts”

Who is online

Users browsing this forum: No registered users and 0 guests