0
I am new to PHP and I am trying to check if there is equal record in the database before registering, but until then everything right, the problem is that I can not check with 3 conditions in WHERE of SELECT ex:
SELECT * FROM datashowreserva
WHERE DATASHOW = '{$datashow}' AND
DATA_RESERVA = '{$data_reserva}' AND
HORARIO_RESERVA = '{$horario_reserva}'
select itself works because it tested in mysql, is the php program that I think is wrong.
Below is what I’ve tried:
$datashow = $_SESSION['select_datashow'];
$data_reserva = $_SESSION['data_reserva_datashow'];
$horario_reserva = $_SESSION['select_horario_reserva_datashow'];
$sql_code_select = "SELECT * FROM datashowreserva WHERE DATASHOW = '{$datashow}' AND DATA_RESERVA = '{$data_reserva}' AND HORARIO_RESERVA = '{$horario_reserva}'";
$sql_query = mysqli_query($server_mysql,$sql_code_select);
if (mysqli_num_rows($sql_query) > 0) {
echo "<script language='javascript' type='text/javascript'>alert('Essa reserva já existe.');window.location.href='Cadastrar_Datashow.php';</script>";
}
'Cause you’re wearing it
{ }
even?– viana
That must be the problem, your date must be like this
2017-08-22
I imagine the user sends22/08/2017
– rray
@rray is informed in the field in the format dd/mm/yyyy then I use it to cause the date to enter in the format yyyy-mm-dd accepted by the bank. //Catch date entered in the HTML field in the format dd/mm/yyyy $data = $_SESSION['data_reserva_datashow']; //Exploding the date to enter the format accepted by BD $dataExplode = explodes('/', $data); $dataNoFormatoParaOBanco = $dataExplode[2]. '-'. $dataExplode[1]. '-'. $dataExplode[0];
– Lucas Barbosa Fonseca
Your field in the field is
date
ordatetime
?– rray
@rray is in date
– Lucas Barbosa Fonseca
Using ' } is wrong? @white
– Lucas Barbosa Fonseca
If you give a
echo $sql_code_select;
how the query is assembled?– rray
@Lucasbarbosafonseca in this situation there I do not usually put.
– viana
@rray is mounted with the variable value instead of the variable in select
– Lucas Barbosa Fonseca
Friend, check the date if it is in this format: 2017-08-22. Otherwise you do not pass in this format should convert the format so:
$datashow = date('Y-m-d',strtotime(str_replace('/', '-', $_SESSION['select_datashow'])))
before carrying out the consultation.– Willian Coqueiro
And you also don’t need {} to declare a variable in a string with "". So if so:
$variavel['offset']
– Willian Coqueiro
@I’ll check the bank?
– Lucas Barbosa Fonseca
In what format is your date in the variable? So: 22/08/2017? If it is should change to the format that the bank accepts it and so: 2017-08-22.
– Willian Coqueiro
To make this conversion before making the query one can do so:
$datashow = date('Y-m-d',strtotime(str_replace('/', '-', $_SESSION['select_datashow'])))
– Willian Coqueiro
the explode is correct, returns yyyy/mm/dd the problem is at another point
– user60252
The schedule reserves as it is in the bank and as it comes from the Second?
– user60252
@Leocaracciolo the time is varchar, I am using html select option
– Lucas Barbosa Fonseca
when vc explodes the date the variable name is $dataNoFormatoParaOBanco and in query vc uses different variable name. Vc checked this?
– user60252
I’m setting up a table in the database to do some tests, only instead of using Sesssions I’ll use dates even though I believe your Sesssions returns the dates correctly
– user60252
I tested with the following data 22/08/2017 - 20/08/2017 - 10:12:00 In the database 2017-08-22 - 2017-08-20 - 10:12:00 I checked the application and gave an alert "This reservation already exists." and threw me on another page. So the error must be in some other part of your application, perhaps in the form, in the construction of the Sesssions, etc.. and that you didn’t post in your question
– user60252
see query SELECT * FROM datashowreserva WHERE DATASHOW = '2017-08-22' AND DATA_RESERVA = '2017-08-20' AND HORARIO_RESERVA = '10:12:00'
– user60252