Jump to content

Pop up window after sql insert


rwigs

Recommended Posts

I have a page form that allows users to enter some information, attach a file, and submit it into my sql. The page works fine. After attempting the sql insert, I have this code:

                $result = mysqli_query($db_conx, $sql );
                if($result){
                    $success_msg = "Thanks for your submission.".$upload_files."<a href='index.php'>Home</a> || <a href='buyad.php'>Buy</a>";
                } else {
                    $errors[] = "<p style='color:red'>There was an error saving your submission. Please contact us.</p>";
                }

So when it is successful, I get the success message at the top of the screen. What I want is to have a pop up window of a defined size that gives the message and the two links. As well as if there is an error, that should be in the pop up window.

 

Now, I have read that pop up windows are a dying trend because most people block them and a good way to go might be a jquery solution. Any input on how to do that?

 

Thanks!

Link to comment
Share on other sites

You don't mention Ajax in your post. Since php is doing the update on the server, it is difficult to have your client produce a pop-up window as a direct result of an insert. The only way to have a pop-up is to do this via an Ajax connection and then you can setup a popup notification or a simple js/jq alert box. The main point is that you must be using Ajax (via JS or JQ)

 

Of course if you don't want to use ajax, then your script will simply call the server via POST and do the update and return a response page to the client and there you can show whatever message you want whether it is on a popup, an alert box, or a simple box/div on your main page, which is what it appears you are currently doing.

 

The main point is you can't do a popup directly from php. You have to utilize js/jq to get that, either using ajax or as part of the page load in the ensuing page load.

Link to comment
Share on other sites

I've not tried this out and it's late in the evening, so if this is a dumb suggestion, then apologies and I'm sure someone will put me straight before too long

 

but .. how about something looking like 

PHP :

echo  ($result) ? '<INPUT TYPE = "HIDDEN" NAME = "myresult" VALUE = "1">' :  '<INPUT TYPE = "HIDDEN" NAME = "myresult" VALUE = "0">';

This will write a hidden input field into your html which can be read when the page is loaded

 

in your HTML :

<BODY onLoad = "check_the_error(document.getElementById('myresult').value)">

when the page is loaded, a javascript function is called, passing the value which was written by the PHP

 

then some javascript somewhere in your header :

function check_the_error(myerror) {

   if (myerror == 1)   etc etc etc   pop up the window, put your code here ......

   etc.

   }

 

 

note : I may have picked up the wrong end of the stick, if so, sorry folks

Edited by grissom
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.