Jump to content


Photo

SQL request


  • Please log in to reply
4 replies to this topic

#1 christo

christo
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 03 May 2006 - 01:00 PM

Once again i'm passing values from html to php but the request is not working and gives [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Problem with query: SELECT * FROM object WHERE city = Montpellier AND transaction = Location AND accomodation = Maison AND nb_rooms = 6 AND price = 1650000 AND age_par = Agence

Unknown column 'Montpellier' in 'where clause'[/quote]

i'm passing the values with
$city = $HTTP_POST_VARS['city'];
$transaction = $HTTP_POST_VARS['transaction'];
$accomodation = $HTTP_POST_VARS['accomodation'];
$nb_rooms = $HTTP_POST_VARS['nb_rooms'];
$age_par  = $HTTP_POST_VARS['age_par'];
$price = $HTTP_POST_VARS['price'];


at the top of the script and my request is
$host = "???";
$user = "???";
$pass = "???";
$base = "???";

$db_conx = mysql_connect($host,$user,$pass) or print("error connection  MySQL !");
mysql_select_db($base, $db_conx) or print("Error connection  DB !");

$query = "SELECT * FROM object WHERE city = $city AND transaction = $transaction
AND accomodation = $accomodation AND nb_rooms = $nb_rooms AND price = $price AND
age_par = $age_par";
$rs = mysql_query($query) or die('Problem with query: '.$query.'<br><br>'.mysql_error());

I need to check if the values i'm passing exist in the DB and if yes show results, but i wonder if linking all the vals with AND is the correct way to go... ?

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 03 May 2006 - 01:08 PM

When using the "WHERE" you got to use single quotes- [!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * FROM sometable WHERE column1='123' [!--sql2--][/div][!--sql3--]
Notice the single quotes around the "123".
This also applys about variables, (IE "WHERE coulmn1='$city' ").

Irui.
Think you're smarty?

(Gone until 20 to November)

#3 christo

christo
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 03 May 2006 - 03:35 PM

That's it ;-)
When i try to display the data from the DB i get an endles While loop with an error...

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\foreign\easyphp1-8\www\agence\test\search.php on line 31[/quote]

$query = "SELECT * FROM object WHERE city = '$city' AND transaction = '$transaction'
AND accomodation = '$accomodation' AND nb_rooms = '$nb_rooms' AND price = '$price' AND
age_par = '$age_par'";

$rs = mysql_query($query) or die
('Probleme avec la requette :'.$query.'<br><br>'.mysql_error());

while(($data=mysql_fetch_array($query))!==false) {                   //I get the Warning here

    echo "<tr>
    <td>".$data['city']."</td>
        <td>".$data['transaction']."</td>
    <td>".$data['accomodation']."</td>
    <td>".$data['nb_rooms']."</td>
    <td>".$data['price']."</td>
    <td>".$data['age_par']."</td>
    </tr>";
}

Any ideas???

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 03 May 2006 - 03:55 PM

change this:

while(($data=mysql_fetch_array($query))!==false) {

to this:

while ($data=mysql_fetch_array($rs)) {

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 christo

christo
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 03 May 2006 - 04:03 PM

I didn't think that would wok !!!

1000 Thanks :-)

christos




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users