Código
function del(id){ $.ajax({ url:'../Controllers/actions.php', type:'POST', data:'code='+id+'&boton=delete_product' }).done(function(ans){ alert(ans); }); }
Código
case 'delete_product': $code = $_POST['code']; $delete = new product(); if($delete->delete($code)){ echo "success"; } else{ echo "there is something wrong"; } break;
Código
function delete($code){ $sql = "DELETE FROM product WHERE id_product='$code'"; if($this->conexion->conexion->query($sql)){ return true; } else{ return false; } $this->conexion->cerrar(); } function show_product(){ $sql = "SELECT * FROM product"; $record = $this->conexion->conexion->query($sql); $item =0; if(!$this->conexion->conexion->query($sql)){ } if($record->num_rows>0){ while($show = $record->fetch_array(MYSQLI_ASSOC)){ $item += 1; echo '<tr> <td>'.$item.'</td> <td>'.$show["code"].'</td> <td>'.$show["product"].'</td> <td>'.$show["price"].'</td> <td>'.$show["stock"].'</td> <td><button class="btn btn-danger" onclick="del('.$show["code"].');"><span class="glyphicon glyphicon-trash"></span></button></td> </tr>'; } //this is for counting number of page } else{ echo '<tr><td colspan="7">no hay registros</td></tr>'; } }