Jump to content

SQL request


christo

Recommended Posts

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 [code]$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'];[/code]

at the top of the script and my request is [code]
$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());[/code]

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... ?
Link to comment
https://forums.phpfreaks.com/topic/8962-sql-request/
Share on other sites

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] * [color=green]FROM[/color] [color=orange]sometable[/color] [color=green]WHERE[/color] column1[color=orange]=[/color][color=red]'123'[/color] [!--sql2--][/div][!--sql3--]
Notice the single quotes around the "123".
This also applys about variables, (IE "WHERE coulmn1='$city' ").

Irui.
Link to comment
https://forums.phpfreaks.com/topic/8962-sql-request/#findComment-32926
Share on other sites

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]

[code]
$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>";
} [/code]

Any ideas???
Link to comment
https://forums.phpfreaks.com/topic/8962-sql-request/#findComment-32968
Share on other sites

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.