I have a jQuery function that is triggered when a button (generated via php) is clicked, the same function is working for me on a link that is created with php as well, but for some reason this one isn't even displaying a error, I checked in firebug and it seems the functions ins't being called.
I have the script on the bottom of my page:
<script src="js/estadoLabs.js"></script> on the bottom of my index page, so it should be working.
The function itself is this one:
$(".btnEliminar").click(function() {
var idAttr = $(this).attr('id');
var id = parseInt(idAttr.substring(12));
var request = $.ajax({
url: "includes/functionsLabs.php",
type: "post",
data: {
'call': 'displayInfoLabs',
'pId':id},
dataType: 'html',
success: function(response){
$('#info').html(response);
}
});
});
I am quite sure the php function isn't to blame because running the $query on SQL makes the change to the table I want. Just in case this is a snippet of the html generated code that has the buttons (they are successfully being displayed).
<input type = "button" value = "Eliminar" class= "btnEliminar" id = "btnEliminar-'.$row['idlab'].'" />
I went over it quite a few times but I didn't find any glaring erros, any help would be very appreciated. Thanks a lot in advance.
EDIT: PHP
Basically thanks to PollyGreek and Rafael the jQuery works, as now when clicking the button it shows me:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in C:\wamp\www\Proyecto\includes\functionsLabs.php on line 179. Line 179 in question is...
function labStatusEliminar(){
if(isset($_POST['pId'])){
$idEliminar = $_POST['pId'];
$msjE = eliminar($idEliminar);
while($row = mysql_fetch_assoc($msjE)){ //<--LINE 179
echo
'<p>El laboratorio: '.$row['idlab'].' ha sido eliminado de la lista</p>';
}
}
}
function eliminar($idEliminar){
$query = "UPDATE labs SET estado=3 WHERE labs.idlab = $idEliminar";
$result = do_query($query);
}
What this function does is taking the id of the button and finding the lab with the same id, then changing that lab's estado to 3.
When doing a select (I know the code is prone to injection >.<) I have been using something like this:
$query = "SELECT bk.idlab , bk.codigolab , bk.capacidad, bk.carrera, bk.ubicacion, bk.estado FROM labs as bk WHERE bk.idlab = $pId ";
So perhaps I need to set an "alias" to my alter statement as well?
and it has been working, I only changed the process within. Added: $result = do_query($query);
– Code Grasshopper Apr 16 '14 at 20:51