0

Upon the case that there is a duplicate query being inserted, i would like to allow the user to select whether or not they would like to update the information specifically with a confirm() popup. The problem that i currently have is that both buttons, OK and cancel, return the result true. I realize that the variable is simply being set to the script code and thus does not retain the value. Is there a way to set the value of confirmation (or another variable) to false when the cancel button is pressed?

if (mysqli_num_rows($duplicateQueryCase1)==1){

                $Confirmation = "<script> window.confirm('would you like to replace field1 with field2?');</script>";
                echo $Confirmation;

                if ($Confirmation == true){
                    $update = "UPDATE students SET phone ='$homeNumber' WHERE first_name ='$firstName' AND last_name ='$lastName' AND birthDate = '$dateOfBirth'";
                    mysqli_query($conn, $update); 
                }
                else{
                    //echo "the element was not updated";
                }

            }    

EDIT: As the following up above is not possible, i am looking for another solution to the if statement triggering something that allows the user (in real time as it inserts one by one) to decide whether they want to update it or not before proceeding to the next element. Any insight or suggestions would be appreciated, thanks.

Xenos
  • 19
  • 5
  • 1
    PHP cannot "trigger a popup" in that way; that is something that needs to happen on the client side. All PHP can do is display some HTML, and react to the user clicking a link, submitting a form, or some other event generated by client-side code (i.e. JavaScript). – IMSoP Jul 03 '18 at 15:31
  • Ok, now that you have stated that php cannot trigger a popup in that sense, do you have any insight for a viable solution? A solution to the if statement triggering something that allows the user (in real time as it inserts one by one) to decide whether they want to update it or not before proceeding to the next element, thanks. – Xenos Jul 03 '18 at 17:40
  • The only way to do it "in real time" is client-side: send an item to the server; if it's a duplicate, ask the user; if they say yes, send it again with an extra flag. Or, pester the user less by finding all the duplicates and rendering a page that lets the user choose actions for all of them. – IMSoP Jul 03 '18 at 20:28
  • 1
    Your updated question is Too Broad. If you wish for this question to be reopened, then will need to research and try something then update your question. (Alternatively, you might like to scrap this page entirely and post a new one later.) – mickmackusa Jul 03 '18 at 22:21

0 Answers0