Jump to content

Recommended Posts

hi geek guys,

 

i'm still learning php...

i'm not yet using classes... that's why

i'm stuck with this script but the problem is i always fall

 

on the "Search found no records."

 

pls do help me, if anyone can edit it...

that's not a problem it could be a great help...

 

take a look at my script  ;)

it's kinda long...please have mercy...

 

thank you very very much....

 

 

<? //Client Search Script


if ($_SESSION['username'] == null){

    header ('Location: http://'.$_SERVER['HTTP_HOST'].'/index.php');
    exit();

}else{

	include('dbh.php');
	$headertitle = 'Client Search';
	print'<br /><br /><span class="welcome"><b>Client Search</b></span>';
	$clientlname = 'clientlname';

if (isset($_POST['Search'])) {	

		if (empty($_POST['clientlname'])) {
			$clientlname = '' ;
		}else{
			$clientlname = "clientlname = '{$_POST['clientlname']}' ";
		}			
        	
		if (empty($_POST['clientfname'])) {
			$clientfname = '' ;
		}else{
			$clientfname = "clientfname = '{$_POST['clientfname']}' ";
		}


		$equery = "SELECT * FROM clientdata WHERE clientid = '$clientid' AND clientlname = '$clientlname' OR clientlname = '$clientlname' " ;
		$result = mysql_query($query); 
		$num_records = @mysql_num_rows ($result);


		if ($num_records <= 0) {
			print "<br /><div align=\"left\">Search found no records.</div><br />";
		}else{

			print '<table width="650" border="0" cellpadding="2" cellspacing="1">';
			print '<TR align="center" bgcolor="#66CC33">
					<td width="10%">Edit/Delete</td>
					<td width="20%">Client ID</td>
					<td width="10%">Client Name.</td>';

			for($i = 0; $i < $num_records; $i++) 
				{
				$row = mysql_fetch_array($result);
				if($i % 2) 
					{ 
					print '<TR align="center" bgcolor="#FFCCCC">';
					} 
				else 
					{ 
					print '<TR align="center" bgcolor="#FF66FF">';
					}
					print'<td><a href="clientsummary.php?clientid='.$row['clientid'].'">Edit</a>/<a href="cliserdel.php?clientid='.$row['clientid'].'">Delete</a></td>';
					$clientid = $row['clientid'];				

					print'	<td> '.$row['clientid'].'</td>';
					print'<td> '.$edata['clientlname'].', '.$edata['clientfname'].'</td>';				

					print '</TR>';
				}
			print '</table>';


		}



}else{


			print'<table width="710" border="0" cellspacing="0" cellpadding="0">
			  <tr>
			    <td align="left" valign="top"><form id="form1" name="form1" method="post" action="clientsearch.php">
			      <table width="550" border="0" align="left" cellpadding="0" cellspacing="0">
			      	<tr>
			      		<td width="138" rowspan="2" align="left" valign="top"><br /></td>
			      		<td width="148" rowspan="2" align="left" valign="top"></td>
			      	    <td colspan="2" align="left" valign="top"></td>
			      	</tr>				      	
			      	<tr>
			      	  <td align="left" valign="top"></td>
		      	      <td align="left" valign="top"></td>
			      	</tr>
			      	<tr>
			      		<td colspan="2" align="left" valign="top">Complete search field below.</td>
			      		<td align="left" valign="top"> </td>
			      	    <td align="left" valign="top"> </td>
			      	</tr>
			        <tr>
			          <td width="138" height="27" align="left" valign="top">Client Last Name: </td>
			          <td width="148" align="left" valign="top"><select name="clientlname" class="form" id="clientlname"><option value="">Any</option>\n';
			            								
							$clientlname = mysql_query('SELECT * FROM clientdata order by clientlname ASC');

							while($clientlrow = @mysql_fetch_array($clientlname)) {

				  		  	print '<option value="'.$clientlrow['clientid'].'">'.$clientlrow['clientlname'].'</option>\n';
				  		
				  		  }				          
			          
			          print'</select></td>
			        </tr>
			        
			         <tr>
			          <td width="138" height="27" align="left" valign="top">Client Last Name: </td>
			          <td width="148" align="left" valign="top"><select name="clientfname" class="form" id="clientfname"><option value="">Any</option>\n';
			            								
							$clientfname = mysql_query('SELECT * FROM clientdata order by clientfname ASC');

							while($clientfrow = @mysql_fetch_array($clientfname)) {

				  		  	print '<option value="'.$clientfrow['clientid'].'">'.$clientfrow['clientfname'].'</option>\n';
				  		
				  		  }				          
			          
			          print'</select></td>
			        </tr>
			        
			       <tr>
			          <td align="left" valign="top"> </td>
		              <td colspan="3" align="left" valign="top"> </td>
	                </tr>		                
			        <tr>
			          <td align="left" valign="top"> </td>
			          <td align="left" valign="top"> </td>
			          <td align="left" valign="top"> </td>
			          <td align="left" valign="top"><div align="right">
			            <input name="Search" type="submit" class="form" id="Search" value="Search" />
		              </div></td>
			        </tr>
			        <tr>
			          <td align="left" valign="top"> </td>
			          <td align="left" valign="top"> </td>
			          <td align="left" valign="top"> </td>
			          <td align="left" valign="top"> </td>
			        </tr>
			        <tr>
			          <td align="left" valign="top"> </td>
			          <td colspan="3" align="left" valign="top"><div align="right"></div></td>
			        </tr>
			      </table>
			        </form>
			    </td>
			  </tr>
			</table>';

}

}

?>

Link to comment
https://forums.phpfreaks.com/topic/116358-help-search-script-error/
Share on other sites

first of all, you dont need that else right at the start.

 

if the session bar username is null, it will exit the script.....

 

secondly, im still reading through it lol :D

 

-Edit, done reading. Theres some problems with the variable setting near the start.

 

change this:

			if (empty($_POST['clientlname'])) {
			$clientlname = '' ;
		}else{
			$clientlname = "clientlname = '{$_POST['clientlname']}' ";
		}			

		if (empty($_POST['clientfname'])) {
			$clientfname = '' ;
		}else{
			$clientfname = "clientfname = '{$_POST['clientfname']}' ";
		}


		$equery = "SELECT * FROM clientdata WHERE clientid = '$clientid' AND clientlname = '$clientlname' OR clientlname = '$clientlname' " ;

 

to this:

			if (empty($_POST['clientlname'])) {
			$clientlname = '' ;
		}else{
			$clientlname = "clientlname = '{$_POST['clientlname']}' ";
		}			

		if (empty($_POST['clientfname'])) {
			$clientfname = '' ;
		}else{
			$clientfname = "clientfname = '{$_POST['clientfname']}' ";
		}


		$equery = "SELECT * FROM clientdata WHERE clientid = '$clientid' AND " . $clientlname . " OR " . $clientlname . " " ;

 

and alter $result to this...

$result = mysql_query($query) or die("lol fail noob  \n".mysql_error()); 

 

Regards ACE

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.