I am making this query sql
from phpmyadmin
and it brings me the data correctly.
SELECT 4am_traficon.ordinthh.codordint, 4am_traficon.ordinthh.responhh, 4am_traficon.ordinthh.fechahh, 4am_traficon.ordinthh.codagencia, 4am_traficon.ordinthh.obshh, 4am_traficon.ordinthh.horash, 4am_traficon.ordinthh.valhorah, 4am_traficon.ordinthh.valminh, 4am_comsysn.ageperso.nomper, 4am_traficon.ordinthh.fecusr, 4am_comsysn.ageperso.codagencia
FROM 4am_comsysn.ageperso
INNER JOIN 4am_traficon.ordinthh ON 4am_comsysn.ageperso.codper = 4am_traficon.ordinthh.responhh
WHERE 4am_comsysn.ageperso.codagencia = "4AM" AND 4am_traficon.ordinthh.responhh = "98520563" AND 4am_traficon.ordinthh.fechahh BETWEEN "2018-12-01" AND "2019-04-25"
ORDER BY fechahh DESC;
When I pass this query to php
it gives me an error in the console it tells me
interal server error
My code php
:
In my connection I am not indicating the database . Could it be a problem since I indicate which database to use in the query?
if(isset($_POST["codagencia"], $_POST["codper"], $_POST["from_date"], $_POST["to_date"]))
{
$connecttwo = mysqli_connect("localhost", "root", "Tr4ff1cfouraM!by?S4atchi");
$connecttwo->set_charset("utf8");
$output = '';
$sql = 'SELECT 4am_traficon.ordinthh.codordint, 4am_traficon.ordinthh.responhh, 4am_traficon.ordinthh.fechahh, 4am_traficon.ordinthh.codagencia, 4am_traficon.ordinthh.obshh, 4am_traficon.ordinthh.horash, 4am_traficon.ordinthh.valhorah, 4am_traficon.ordinthh.valminh, 4am_comsysn.ageperso.nomper, 4am_traficon.ordinthh.fecusr, 4am_comsysn.ageperso.codagencia\n"
. "FROM 4am_comsysn.ageperso\n"
. "INNER JOIN 4am_traficon.ordinthh ON 4am_comsysn.ageperso.codper = 4am_traficon.ordinthh.responhh\n"
. "WHERE 4am_comsysn.ageperso.codagencia = '".$_POST["codagencia"]."' AND 4am_traficon.ordinthh.responhh = '".$_POST["codper"]."' AND 4am_traficon.ordinthh.fechahh BETWEEN '".$_POST["from_date"]."' AND '".$_POST["to_date"]."'\n"
. "ORDER BY fechahh DESC';
In my code ajax
I am correctly sending the data
Code Ajax
:
$('#filter').click(function(){
from_date = $('#from_date').val();
to_date = $('#to_date').val();
codagencia = $('#brand').val();
codper = $('#show_product').val();
//console.log(codcli, from_date, to_date);
if(codagencia != "" && codper != "" && from_date != '' && to_date != '') {
$.ajax({
url:"user_data.php",
method:"POST",
data:{codagencia:codagencia, codper:codper, from_date:from_date, to_date:to_date},
beforeSend: function() {
$('#order_table').css('background', 'url(/img/ajaxloader.gif) no-repeat center top')
},
complete: function(){
$('#order_table').css('background', 'none')
},
success:function(data)
{
$('#order_table').html(data);
}
});
} else{
alert("Selecione agencia, usuario y rango de fechas");
}
});
The 500 error occurs when the server code (PHP) has errors.
In this case your code has syntax errors. You don't close the
if
, and the way to concatenate the SQL query is dubious, using\n
instead of simple blank spaces... you don't need to use so many dots to join lines either, you can write it in a single variable.Try it like this, in this code I have saved the POST data in variables using a ternary, then using them is much clearer and easier.