rwigs Posted May 22, 2015 Share Posted May 22, 2015 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! Quote Link to comment https://forums.phpfreaks.com/topic/296455-pop-up-window-after-sql-insert/ Share on other sites More sharing options...
ginerjm Posted May 22, 2015 Share Posted May 22, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/296455-pop-up-window-after-sql-insert/#findComment-1512484 Share on other sites More sharing options...
jcbones Posted May 22, 2015 Share Posted May 22, 2015 If you decide to do this by AJAX, then here is a tut for you. http://http://www.jquery-tutorial.net/ajax/introduction/ Quote Link to comment https://forums.phpfreaks.com/topic/296455-pop-up-window-after-sql-insert/#findComment-1512485 Share on other sites More sharing options...
grissom Posted May 22, 2015 Share Posted May 22, 2015 (edited) 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 May 22, 2015 by grissom Quote Link to comment https://forums.phpfreaks.com/topic/296455-pop-up-window-after-sql-insert/#findComment-1512489 Share on other sites More sharing options...
grissom Posted May 23, 2015 Share Posted May 23, 2015 Oops, that should be ID="myresult" not NAME = "myresult" Quote Link to comment https://forums.phpfreaks.com/topic/296455-pop-up-window-after-sql-insert/#findComment-1512493 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.