Why does this php/ajax query fail?
- by Ashley Brown
I'm ajaxing over to this php file.
$a = 'old';
$b = 'new';
if ($_POST['info-type'] == $a || $b)
{
$info = $_POST['info-type'];
$query = "SELECT * FROM `tld` WHERE type = '".$var."'";
}
$query = "SELECT * FROM `tld` ";
$result = mysqli_query($link,$query);
while($row = mysqli_fetch_assoc($result))
{
echo '<div>'.$row['something'].'</div>';
}
The data posted is either 'all' 'new' or 'old'.
If i send the data as either new or old, the script works and outputs as expected.
If the posted data is neither new or old but all instead, it fails and don't show any errors or respond anything back. (I've monitored via dev tools aswell)
So, I tried this
if ($_POST['info-type'] == $a || $b)
{
$info = $_POST['info-type'];
$var = "SELECT * FROM `tld` WHERE type = '".$var."'";
} elseif ($_POST['info-type'] == 'all'){
$query = "SELECT * FROM `tld` ";
}
But the script still fails. If i fully remove the IF statements and use the query without the WHERE clause like it is after the elseif, it works?