Jump to content

Weird problem with SELECT script. Please help!


patheticsam

Recommended Posts

Hi!

 

I'm havving a little issue with a simple search script with SELECT command. I just changed hoster to go with Godaddy and it seems that the select does not work anymore...(it was working perfectly on previous server).

 

Here's a little bit of my code :

 

here's the search form (pretty simple) :

 

<form enctype="multipart/form-data" action="search_result.php" method="POST" target="main"> 
  <td style="text-align: left;" colspan="2"><input type="text" name="search" style="width: 300px;"><input type="submit" value="Rechercher"></td>
</form>

 

And here's the result part :

 

<?php 

mysql_connect("localhost", "user", "pass") or die(mysql_error()); 
mysql_select_db("db") or die(mysql_error()); 

$data = mysql_query("SELECT * FROM `opportunite` WHERE `entreprise` LIKE '%$search%' ORDER by `categorie`") 
or die(mysql_error());

while($info = mysql_fetch_array( $data )) 
{ 
echo "
<table border=\"0\" celppadding=\"0\" cellspacing=\"0\" style=\"font-weight: bold; width: 850px;\">  
  <tr onmouseover=\"mover(this);\"  onmouseout=\"mout(this);\">
   <td style=\"width: 200px;\">".$info['entreprise']."</td>
   <td style=\"width: 150px;\">".$info['vendeur']."</td>
   <td style=\"width: 200px;\">".$info['categorie']."</td>
   <td style=\"width: 150px;\"><a href=\"view_client.php?cmd=view&id=".$info['id']."\">Visionner / Modifier</a></td>
   <td style=\"width: 150px;\"><a href=\"delete_client.php?cmd=delete&id=".$info['id']."\">Supprimer</a></td>

  </tr>
</table>
     ";
}
?>

 

 

 

The problem is when I make a search I always get all the results in db instead of the specific word im looking for....It was working perfectly on the previous server....????

 

Any help is appreciated!

 

Thanks

 

 

I would assume that $search is not getting defined - which I think would result in all the recrods getting pulled. Have you validated the query getting generated? I always create the queries as a string variable so I can echo to the page for debugging purposes. Try this:

 

$query = "SELECT * FROM `opportunite` WHERE `entreprise` LIKE '%$search%' ORDER by `categorie`";
echo "Query: $query";
$data = mysql_query($query) or die(mysql_error());

 

Is it possible that it's due to PHP version 5?

Think about it. A PHP update causing a MySQL query to return different results? Not possible.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.