PHP Search engine for mysql
Ok. I have this little bit of code that is supposed to use text and boolean fields in an html form to search a mysql database. This is a learning project so no rush.
The idea is it is supposed to check the text fields for input and look and see if the checkboxes have anything in them. The checkboxes work fine but when I add the code for the textbox postcode I get the dreaded.
"Warning: mysql_real_escape_string() [function.mysql-real-escape-开发者_如何学JAVAstring]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\criteriasearch.php on line 36"
I cannot quite figure this out. Here is the code for the checkboxes. This works fine on it's own.
if(isset($_POST['search']) && !empty($_POST['search'])){
foreach($_POST['search'] as $key=>$value){
if($value==1) $search[] = "$key";
$searchstring = implode(' AND ', $search);
}
When I add the following code:
$post_map = array(
'postcode'=>'candidate_contact_details.postcode'
);
if(isset($_POST['postcode']) && !empty($_POST['postcode'])) {
foreach ($_POST['postcode'] as $key) {
if (array_key_exists($key, $post_map));
$search[] = $post_map[$key] . '=' . mysql_real_escape_string($value);
}
It just gives me access is denied on that section but the first section works. I am pretty sure I have something wrong with brackets or such but cannot for the life of me work it out and any assistance would be appreciated.
Thanks In Advance
Try passing the link identifier from your mysql_connect call as the second parameter to mysql_real_escape_string. In order to function it requires an already established MySQL connection.
精彩评论