1

Hello i wrote some PHP code:

$number = $_POST['number'];
$start = $_POST['start'];
$end = $_POST['end'];
$user_name = $_POST['user_name'];
$phone = $_POST['phone'];

$validation_query = "SELECT * FROM `rezerwacje_miejsc` WHERE 
`NR_MIEJSCA`='$number' AND `START` BETWEEN '$start' AND '$end' OR `KONIEC` 
BETWEEN '$start' AND '$end';";

But every time SQL is returning any value if is between but ignores number - I've tried to use '$number', $number or even wrote number manually. Still no effect any ideas?

Luke_Nuke
  • 461
  • 2
  • 6
  • 23

2 Answers2

2

This is beacause of your "AND". I will short the SQL a little bit to explain it better:

SELECT * FROM table WHERE condition1 AND condition2 OR condition3

This will simply link the three conditions together. So if your Condition3 is true, Condition1 & Condition2 doesn't matter.

I think if you use brackets it could work:

 SELECT * FROM table WHERE condition1 AND (condition2 OR condition3)

Hope this helps you

IX33U
  • 85
  • 4
1

Try this.

$number = (int)$_POST['number'];

$validation_query = "SELECT * FROM `rezerwacje_miejsc` WHERE 
`NR_MIEJSCA`=".$number." AND (`START` BETWEEN ('$start' AND '$end') OR `KONIEC` 
BETWEEN ('$start' AND '$end'))";

You need to pass the integer value. Secondly you need to () so it will read the query to satisfied both conditions NR_MIEJSCA=".$number." And START BETWEEN ('$start' AND '$end') OR KONIEC BETWEEN ('$start' AND '$end'))" but OR condition on the second part.

Hope this helps.

Thanks.

SRK
  • 3,476
  • 1
  • 9
  • 23