I'm having trouble with making a deleting system in PHP,Javascript and AJAX. I've done it before but this time PHP and AJAX won't make contact, nor will the Javascript script do anything.
In the Javascript file(server-log.js) alerting something won't work, it will not come. This also won't work for the AJAX/PHP handler file(server-log.handler.php). The console bug doesn't give any bugs in return, the URLs in all the files are also correct. That's because I can find every file with the console bug from Chrome
The JS script(server-log.js):
$('.btn btn-xs btn-danger').click(function(){
var press = $.this.attr('id');
var press_url = 'action=delete&id='+press;
$.ajax({
type: 'POST',
url: 'panel/includes/handlers/server-log.handler.php',
data: press_url,
success: function(responseText)
{
$.parseJSON(responseText);
/* If and else controlling system */
if(responseText.indexOf(1) > -1)
{
$("#danger").append('<strong>Helaas!</strong> Het is niet gelukt om de gevraagde log rij te verwijderen');
}
else if(responseText.indexOf(2) > -1)
{
$("#danger").append('<strong>Helaas!</strong> Het opgegeven ID nummer is niet geldig');
}
else if(reponseText.indexOf(100) > -1)
{
$("#success").append('<strong>Goed!</strong> De gevraagde log is succesvol verwijderd');
}
else
{
$("#info").append('<strong>Info:</strong> Er is helaas een onbekende fout opgetreden <i>2255200914</i>');
}
}
});
});
The HTML part(server-log.php)
<div class="alert alert-success" style="display: none;" id="success"></div>
<div class="alert alert-danger" style="display: none"; id="danger"></div>
<div class="alert alert-info" style="display: none;" id="info"></div>
<div class="error-log sscroll">
<ul>
<form method="post">
<?php
while($arrayLogs = $arrayqLogs->fetch_array())
{
?>
<li>
<span class="green">[<?php echo $arrayLogs['date']; ?>]</span>
<span class="red">[<?php echo $arrayLogs['action']; ?>]</span>
[<?php echo $arrayLogs['name']; ?>] <?php echo $arrayLogs['url']; ?>
<button class="btn btn-xs btn-danger" name="deleting" id="<?php echo $arrayLogs['id']; ?>"><i class="fa fa-times"></i></button>
</li>
<?php
}
?>
</form>
</ul>
</div>
The PHP handler part(server-log.handler.php)
<?php
include_once '../config.php';
if(isset($_POST['action']) && $_POST['action'] == 'delete')
{
$intAction = trim($_POST['id']);
$error = array();
$bolean = false;
# Prepared statement
$stmt = $mysqli->prepare("SELECT id,name,action,url,date FROM logs WHERE id = ?");
$stmt->bind_param('i', $intAction);
$stmt->execute();
$intStatement = $stmt->num_rows();
$stmt->close;
/* Controlling part */
if($intStatement == 0)
{
$error[] = 1;
$bolean = true;
}
elseif(!ctype_digit($intAction))
{
$error[] = 2;
$bolean = true;
}
// Deleting and notifying
if($bolean == false)
{
$stmt = $mysqli->prepare("DELETE FROM logs WHERE id = ?");
$stmt->bind_param('i', $intAction);
$stmt->execute();
$stmt->close();
# Returning error code
$error[] = 100;
}
/* Returning the value in a readable way */
header('Content-Type: application/json');
echo json_encode($error);
}
?>
So this isn't the first time I'm making this on my website, but I haven't done it often either so I think I've done many things wrong. I'm thanking you guys in advance for helping, English isn't BTW my mother tongue so sorry for any grammar/misspelled words.
console.log()stops responding?SELECTquery, but never using the result that it returns?prepare()was successful. It doesn't tell you anything about whether the query returned anything. Use$stmt->num_rows.