Jump to content

Recommended Posts

Hi guys my name is Chris i'm on this forum and in php programming so i have a few questions, i hope somebody can help me.

 

So:

 

i' m trying  to make a real estate website and i have some difficulties with the search form

 

the form has 5 fields: price_from; price_to; number_rooms, location and numb_square_meters

the data base has 5 columns: id, price, location, numb_square_meters, number_rooms

 

 

 

For the price fields i use an input type field

For numb_rooms i use a select type field with options like(vila, condo, 4 bedroom apartaments..something like that and ALL OPTIONS option)

For location and square_meters is the same way as for numb_rooms

 

The problem is this actually there are more than one:

1.When i choose the option "ALL OPTIONS" in the LOCATION field in my form i want it to retrieve every location from the SQL DB if not to retrieve one of the other options

2. If let say the user fills the price fields but the other ones remain with the ALL OPTIONS option selected i want it to retreive only the rows that is in that price range no matter the location number of rooms or the square meters

 

i want to point out the english is not my maternal language , so if you spot some  spelling or grammar errors i apologize.

 

This a part of my code...

 

<form method="post" action="index.php" enctype="multipart/form-data">

<input type="hidden" name="id">

Price <input type="text" name="price">

Price2 <input type="text" name="price2" />

 

 

 

Square_meters<input type="text" name="Square_meters">

 

Location<select name="Location">

<option>Bucuresti</option>

    <option>Iasi</option>

    <option>Brasov</option>

    <option>Focsani</option>   

</select>

Numb_rooms<select name="Numb_rooms">

<option>Garsoniera</option>

    <option>2 Camere</option>

    <option>3 Camere</option>

      <option>4 Camere</option>

    <option>Vila</option>   

</select>

<input type="submit" name="send" value="Search">

</form>

<?php

header("content-type: image.jpg");

 

 

 

if(isset($_POST['send']))

{

require_once("conexiune.php"); (this is my conect to sql database script)

$id = $_POST['id'];

$price = $_POST['price'];

$price2 = $_POST['price2'];

$square_m = $_POST['Square_meters'];

$location = $_POST['location'];

$numb_rooms = $_POST['Numb_rooms'];

$selectie = mysql_query("SELECT * FROM apartamente WHERE id = '$id' && Pret>='$price'&& Pret<='$price2' && Location = '$location' && Square_meters='$Square_meters' && Numb_rooms = '$Numb_rooms ' ");

 

 

while($row = mysql_fetch_array($selectie,MYSQL_ASSOC))

{

 

print"<tr><td>";

print $row['id'];

print"</td><td>";

print $row['Pret'];

print"</td><td>";

print $row['Nr_camere'];

print"</td><td>";

print $row['Suprafata'];

print"</td><td>";

print $row['Locatie'];

print"</td><td>";

print $row['Descriere'];

print"</td><td>";

You have some serious security issues with your code, by the way. You really need to implement Input Validation and Output Escaping to your script, otherwise you're wide open to anyone who wants to attack the site.

 

Also, why do you have this in the middle of the code?

header("content-type: image.jpg");

Not only do I see no logical reason for it to be there, but it will not work in any case. See the "HEADER ERRORS" threat stickied at the top of this forum for more info.

 

PS: Please use the


tags around your code, as it helps make both your post and your code a lot easier to read. Thanks.

Yes i know the problems with the security, but i'm way far from finishing, about the header....the logic is that in the database i have a field where i store images, so when i retrieve data and display it it will show some images too.

the problem is that a user has to either fill out all the fields in the form or neither one....i want it to be possible to complete some of them and the other ones to be ignored..and i don't how to make an sql query to extract the proper rows

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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