PHP Search Problems and concat

Discussion in 'Programming' started by tdd1984, Sep 20, 2007.

  1. #1
    Guys I'm using


    
    
    	<form action="/adminstration/sales-completed.php" method="get">
    	  			<table>
    	  				<tr><td>Sales ID:</td><td><input type="text" name="sales_id"></td></tr>
    	  				<tr><td>First Name:</td><td><input type="text" name="first_name"></td></tr>
    	  				<tr><td>Last Name:</td><td><input type="text" name="last_name"></td></tr>
    	  				<tr><td>Phone Number:</td><td><input type="text" name="Phone"></td></tr>
    	  				<tr><td></td><td><br/></td></tr>
    	  				<tr><td><a href="/adminstration/sales-completed.php?viewall=1">View All</a></td><td><input type="submit" value="search" name="submit"></td></tr>
    				</table>	  		
    				
    				
    	  		</form>
    	 
    	  	<table border="0" width="100%">
    	  		<th style="padding:5px;">Sales Id#</th><th style="padding:5px;">First Name</th><th style="padding:5px;">Last Name</th><th style="padding:5px;">Total Price</th><th style="padding:5px;">Date</th><th style="padding:5px;">Details</th>
    	  	   <?PHP 
    
    
    
    		   include("paging.php");
    	  	   $sql = "SELECT * FROM sales_received WHERE order_processed = '1'";
    	  	   
    	  	   if(isset($_GET['sales_id'])) { $sql .= " AND id =  " . mysql_escape_string($_GET['sales_id']) . " "; }
    	  	   if(isset($_GET['first_name'])) { $sql .= " LIKE first_name =  '%" . $_GET['first_name'] . "%' "; }
    	  
    
    PHP:
    for some reason when I search for sales id only, it adds the first name too? It should not add the first name if the first name input field is left blank, any one know why this is doing that for?
     
    tdd1984, Sep 20, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    isset() only checks if the var is not NULL, in this case, it is "" (empty string of length 0)

    So you would need:
    if (isset($_GET['first_name']) && $_GET['first_name'])
     
    krt, Sep 20, 2007 IP