I want an en to be executed, PHP
but only if any of the 4 buttons are clicked . The problem is that when the page loads, the instruction inside the with is still executed , but I only need it (as I said before) to only be executed when some of those buttons are clicked and nothing else.insert
mysqli
if
insert
Maybe I'm putting the if
, the parentheses wrong, or the use and location of the operators. I have already tried some other combinations and it continues to enter insert
without even having clicked on the buttons. As you can see I put all the conditions in the same if
, maybe I should separate it into different ones if
. I hope you can tell me what would be more effective and that works of course. The code of PHP
is:
if(isset($_POST['Ant']) && !empty($_POST['Ant']) ||
(isset($_POST['Sig']) && !empty($_POST['Sig'])) ||
(isset($_POST['Pri']) && !empty($_POST['Pri'])) ||
(isset($_POST['Ult']) && !empty($_POST['Ult'])))
{
$sql=mysqli_prepare($cxn,"Insert into esttips (ID,NroTips,UserIP,Fecha)
Values (?,?,?,?)");
mysqli_stmt_bind_param($sql,'siss',$id,$F,$ip,$fecha2);
if (!mysqli_stmt_execute($sql)) {die('Error: ' . mysqli_error($cxn));}
}
I will explain a little better. I must clarify that I have all the code in the same file ( index.php ). The button clicks event is done in JQuery
making use of AJAX
which is already working:
$('body').on('click', '#Ant, #Sig, #Pri, #Ult', function(e) {
...
...
}
I only need, as I mentioned at the beginning, that when any of the buttons is clicked ( #Ant
, #Sig
, #Pri
, #Ult
) it makes the insertion in the MySQL database that I have. But it can be seen that since all the code is in the same file, when loading the page it already inserts the values, when I only want it to do so only when a button is clicked.
Can everything be done in the same index.php or should I do the php thing separately in another file and then from the index.php make the call?
From what I see, you are missing a parenthesis to make it 4 blocks inside the if condition: