DISCLAIMER: I am aware of SQL Injection, I am getting the function done first.
My delete from button does not seem to remove my row in my SQL table
products-one-time.php
This is the output of my foreach, the numbers below the delete button are the groupids, just to show they are unique.
this is the code for the delete button, it redirects to clinics_buttons.vc.php on click.
<a href="clinics_buttons.vc.php<?php echo '?delete-coupongroup='.$rowCouponGroup['groupid']; ?>" onclick="return confirm('Delete this group?');">
<button class="btn btn-danger btn-sm full_width" data-toggle="modal">
<i class="fa fa-edit"></i>DELETE
</button>
</a>
<?php echo $rowCouponGroup['groupid']; ?>
clinics_buttons.vc.php
<?php
session_start();
$routePath = "../";
require_once($routePath . "_config/db.php");
$dbConfig = new config_db();
$db = $dbConfig->init();
$delete_coupongroup = $_GET['delete-coupongroup'];
if (isset($_GET['delete-coupongroup'])) {
$stmt = $db->prepare("DELETE FROM `product_onetime` WHERE groupid = $delete_coupongroup");
$stmt->execute();
header('Location: ' . $_SERVER['HTTP_REFERER']);
}
?>
this is the product_onetime table
What I see is that my code seems to look like they are connected, but the delete button does not work. I tried to manually do the SQL in phpmyadmin, for example:
DELETE FROM `product_onetime` WHERE groupid = 5
Doing it manually works, but the php/sql does not. Would like some input.
My guess is that the file clinics_buttons.vc.php is not executed at all, because the code we see in the question is inside a <form>. In this case, the button behavior overrides the link behavior and the browser will submit the form instead of following the link.
You should be able to see that in the network tab of your development tools in your browser.
As a quick fix, change the button from a submit button into a push button:
<button type="button" class="btn btn-danger btn-sm full_width" data-toggle="modal">
<i class="fa fa-edit"></i>DELETE
</button>
A better solution would be not to use a button at all. Just make the link look like a button by using CSS styling. Or alternatively, remove the code from outside the outer form tag and give it its own form using clinics_buttons.vc.php as the form action.
Related
html:
<button type="button" class="btn btn-outline-danger btn-icon-text" id = "LOAD">
<i class="mdi mdi-upload btn-icon-prepend"></i>LOAD
</button>
php:
<?php
if (isset($_SESSION['LOAD']))
{
exit();
}
?>
when i click the button, nothing happens. sorry i am really new to html and php. i have tried multiple other methods but none work :(
<button type="button" class="btn btn-outline-danger btn-icon-text" id = "LOAD">
<i class="mdi mdi-upload btn-icon-prepend"></i>LOAD
</button>
That's just a HTML code, so it will not trigger anything. You need little bit javascript.
Also remember, php loads before javascript. So you can't trigger php with javascript if you don't use AJAX or redirect etc.
<script>
document.getElementById("LOAD").onclick = function(){
window.location.href = window.location.href+"?LOAD=1";
}
</script>
If you add that javascript code, button will refresh the page and redirect the same page with GET parameter.
You can control the GET parameter on the PHP side.
<?php
if (isset($_GET['LOAD']))
{
exit();
}
?>
It's not efficient path but if you understand the mechanics, you can figure it out.
Research AJAX.
You are not assigning the button name (which is different from the id)
try name="LOAD" as in:
<button type="button" class="btn btn-outline-danger btn-icon-text" id="LOAD" name="LOAD">
<i class="mdi mdi-upload btn-icon-prepend"></i>LOAD
</button>
</div>
I am not able to reload the php page after a certain button is pressed. That is there is no change until I reload the page by myself. The php script is:
<?php
// Initialize the session
session_start();
if (($_SESSION['ShowGenerated'] == 'hidden'))
{
$class = 'hidden';
}
else if (($_SESSION['ShowGenerated'] == 'visible'))
{
$class = 'show';
}
?>
<html>
<head>
....
<td><button id="pdf" name="Change" class="btn btn-primary"><i class="change-a"" aria-hidden="true"></i>Click Here</button></td>
...
On clicking "Click here" button, Change.php is called where $_SESSION['ShowGenerated'] value is generated. How do I load the current page or a URL to show a change?
EDIT: Instead of reloading the whole page, can I only reload to check if the $_Session has changed in the html page?
Try to put tag inside :
<button id="pdf" name="Change" class="btn btn-primary"><i class="change-a"" aria-hidden="true"></i>Click Here</button>
like this
I have been having problems passing Javascript variable to php using ajax on the same page.I have a try.php page and once a button is clicked, I want a value sent to try.php variable without reloading the page..
This is my form code,I am actually looping trough a database record
<?php
foreach($vars as $var){
?>
<form method="POST">
<button class="btn btn-warning btn-sm btn_edit" name="btn_edit" value="<?php echo $var['mem_id'];?>">
<span class="glyphicon glyphicon-pencil"></span></button>
<?php
}
?>
Here is my ajax code
$('.btn_edit').click(function(e){
var uid = $(this).val()
$.post("try.php",{ btn_edit : uid},
function(){
});
console.log(uid);//I could see the id logged on console
$('#edit_details').modal('show');
e.preventDefault();//prevent the form from submitting
});
On my try.php page, I have this code to check if it passed succesfully
<?php if(isset($_POST['btn_edit'])){
$user_id = $_POST['btn_edit'];
}?>
There are two modifications need to be done:
Change 1: Only input elements can have value attribute. And as you have <button>, it should be assigned with some other attribute which can be captured using jQuery, so here I am going to use data-bind attribute with it.
<button class="btn btn-warning btn-sm btn_edit" name="btn_edit" data-bind="<?php echo $var['mem_id'];?>">
And then,Change 2:
Get data-bind value with jQuery like this:
$('.btn_edit').click(function(e){
var uid = $(this).attr('data-bind'); // Using attr, not val()...
$.post("try.php",{ btn_edit : uid},
function(){
});
console.log(uid);//I could see the id logged on console
$('#edit_details').modal('show');
e.preventDefault();//prevent the form from submitting
});
I made a JQuery function the one deletes the row I selected. I know that the option exist in the DataTables option, but I want to do by myself, because I prefer to not use AJAX, just JQuery and JSON.
The problem appears when I search some specify row in the datatable with the search option, then I click the button to delete, and nothing happens. The other mistake is when I click to the next page, then, all the rows from that page will not work either.
Do you guys know what this could be?
Here I let my JQuery function:
$(document).ready(function() {
$( ".botFactura" ).click(function(e) {
alert("jkn");
idFact = this.id;
var confirmacio = confirm("Segur que vol esborrar la factura "+idFact);
/*if(confirmacio){
$.post("operacions/borraFact.php", {idFact: idFact}, null, "json").done(function(data){
alert(data.missatge);
})
}*/
});});
Then, I have the JSON file there:
<?php
include("../connexio.php");
$idFact= $_POST['idFact'];
$arrayDatos = array();
if($idFact!=""){
$borrar = 'DELETE FROM factures WHERE id="'.$idFact.'"';
//$connBorr = mysqli_query($conn,$borrar);
$arrayDatos['missatge'] = "Factura ".$idFact." esborrada!";
}else{
$arrayDatos['missatge'] = "No s'ha trobat";
}
echo json_encode($arrayDatos);
?>
I call the $(".botFactura") there:
<button type="button" name="<?php echo $line2['id']?>" id="<?php echo line2['id']?>" class="btn btn-danger botFactura">
<span class="glyphicon glyphicon-trash"></span>
</button>
<button type="button" name="<?php echo $line2['id']?>" id="<?php echo $line2['id']?>" class="btn btn-success botFactura">
<span class="glyphicon glyphicon-pencil"></span>
</button>
Finally, I'll upload some graphical example about what's my problem:
:The first one, is when the page works correctly
Then,the first issue appears when: I change the page of the table. As we can see, I click and nothing happens
The same issue appears when I try to search some specific row into the search box.
Well, I would really appreciate if someone could help to explain why this is not working! Thank you!
I don't know which version of jQuery you are using but if you are jQuery 1.9 or upper version try this
$( document ).on('click', '.botFactura', function(e)
or if you are using lower version try this
$( ".botFactura" ).live('click', function(e)
im trying to show the user's name $user on a button but i cant figure how to do it:
here's some of the code
include ("config.php");
include ("adminchk.php"); // Check if user is admin
include ("getdir.php");
include ("lang/lang_".$lang.".php");
if (isset($uStat) and $uStat===TRUE)
{
echo $GLOBALS['l_menuWelcome'] . " " . $user."\n";
if ($admin===TRUE) echo "*";
echo "<div class='quote'>\n"; ... etc
and here's the button code :
<button type="button" class="btn btn-default" onclick="location.href='userconnect.html'" >$user</button>
thanks for your time :)
To print a PHP variable in the middle of some HTML, you need to wrap it in PHP tags and use echo. So assuming your button code comes from a PHP file, the code looks like this:
<button type="button" class="btn btn-default" onclick="location.href='userconnect.html'" >
<?php echo $user; ?>
</button>
Documentation