RE: [PHP-WIN] Re: PHP Search DB Table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Okay, thank you all again for your input, I have tried a number of suggestions to work out what is happening. Just to reiterate here is the search form which is on a different page.
 
<form action='datasearch.php' method='POST'>
<div id ="options">
<p><label>Search by Client ID<br /><input type="text" name="searchx" /></label></p>
<p><input type="submit" value="Search" /></p>
</div>
 
shown below is the datasearch.php page
 
<?php
$term = $_REQUEST['searchx'];
mysql_connect("localhost", "root", "christmas") or die (mysql_error());
mysql_select_db("moneyl") or die(mysql_error());
$query = "SELECT * FROM clients WHERE clientid = '%".$term."%'";
echo $query . '<br />'; 
echo $term . '<br />';
$result = mysql_query($query);
echo"<table border='1'>";
echo "<tr><th>Client ID</th> <th>Feeearner</th> <th>First Name</th>
<th>Middle Name</th>
<th>Last Name</th>
<th>House/Flat Number</th>
<th>Address</th>
<th>Postcode</th>
<th>Gender</th>
<th>Date of Birth</th>
<th>Landline</th>";
while($row = mysql_fetch_array( $result ))
{
echo "<tr><td>";
echo$row['clientid'];
echo"</td><td>";
echo$row['feeearner'];
echo"</td><td>";
echo$row['firstname'];
echo"</td><td>";
echo$row['middlename'];
echo"</td><td>";
echo$row['lastname'];
echo"</td><td>";
echo$row['hfnumber'];
echo"</td><td>";
echo$row['address'];
echo"</td><td>";
echo$row['postcode'];
echo"</td><td>";
echo$row['gender'];
echo"</td><td>";
echo$row['dob'];
echo"</td><td>";
echo$row['landline'];
echo"</td></tr>";
}
echo"</table>";
?>
 
The printout of the query reveals this
 
SELECT * FROM clients WHERE clientid = '%%'

the echo of the value $term just showed a blank line.
 
Essentially the numbers entered into the search box which I am retrieving using
 
$term = $_REQUEST['searchx'];

are not being pulled through, am I using the correct funtion? I tried GET and POST just to see what would happen an no joy.
So why does the above just display a blank value even when there are numbers in the search box? I am very much a novice at this so it is not impossible that I am making a very very basic mistake here but from the tutorials I have seen this should work.
 
Many thanks for your help, this is the first time I have used this method to obtain help and I have been very impressed with both the speed and quality of the repsonse.
 
Kind Regards
 
Oliver

 


> From: aristotlekhan@xxxxxxxxxxxxx
> To: harlequin2@xxxxxx; php-windows@xxxxxxxxxxxxx; php-db@xxxxxxxxxxxxx; robleyd@xxxxxxxxxxx
> Date: Tue, 14 Dec 2010 12:55:31 +0000
> Subject: RE: [PHP-WIN] Re: PHP Search DB Table
> 
> 
> David, Sascha thank you both for your help. Using the query 
> 
> $query = "SELECT * FROM clients WHERE clientid = '$term'";
> echo $query . '<br />';
> $result = mysql_query($query);
> 
> as suggested printed out the below
> 
> SELECT * FROM clients WHERE clientid = ''
> 
> This seems to indicate that it is not seeing the value within the single quotes. However a slight caveats to that
> If I change what is contained within the quotes to a specific number then it does read it, for example
> 
> SELECT * FROM clients WHERE clientid = '123456';
> 
> So it is only when I enclose a value that it doesn't compute, I tried putting the $term within %% like so
> 
> $query = "SELECT * FROM clients WHERE clientid = '%".$term"%'";
> 
> however this just returns we page not found, possibly because I need to use the LIKE parameter in there somewhere?
> 
> Many thanks for all your help on this
> 
> Kind Regards
> 
> Oliver

 
> 
> 
> 
> 
 		 	   		  

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux