How do I stop loading php page?
I have an HTML page (mypage.com/index.html) which calls a php page (mypage.com/task.php)..
When index executes the php page the browser ends up on my page.com/task.php which I don't want.
I have a form on the main page with graphics, menus, etc. I don't want the visited to leave that main page after the hit the submit button on the form. How do I stop the browser leaving the calling page when it calls a php page? I want this to happen in the background.
I'm confused about your page names. Are the pages REALLY 'named' : mypage.com/index.html. Normally a web page is named something like "index.html" or "task.php".
No, Im just using that as an example. Here is the sequence...
I go to the main /index.html page (home page) which has a simple form for input.
I enter a string and hit the submit button.
The index page sends that info to my /task.php page on the server which posts the input to
mysql also on the server.
The php page sends an echo (only because I programmed an echo in there which may be the
problem) which prints on a new browser page, taking me off the original main page.
I want to make sure that when someone hits the submit button on the main page that they dont leave the main page.
Now here are my thoughts. I suppose if I program php to return some html info it will have to put it on a new page. However, if the php page sends no html info maybe it will have no reason to leave the original calling page.
I will have to remove that echo statement and test that theory. What are your thoughts. Am I thinking right?
Thinking purely about design here......
The index page (by default) is usually the main page of a 'site'. You have picked up on that by naming your first page 'index.html'. Question is - is there any php in this page? If not you have made it a tad more complicated to get some dynamic content to show up there. Moving on tho - having a main page like 'index.html' gives you a landing place on the web for your entire site, no? So - how much individual functioning do you want this page to do for you? As you add to your site, you're going to be wanting to have other pages appear to your users, not just the index. In your question above, perhaps (perhaps!) you might want to move that input form from your main page (index.html) to a page created to handle that input and let task.php send the form, wait for it, receive and process it (and any errors) and have a 'return' button on the task.php screen to send you back to the index.html screen. And repeat that scenario when you come up with task #2.
Just my $.02
That IS good advise and I thank you for the idea. My issue is this...why does the entire process take me away from the main index.html page (or it could be any secondary page for that matter). What is it about the execution of that php code that sends me to a second page (the one that prints the echo I put in there). The more I think about it the more I suspect it's the echo statement itself. It sends that back to the browser and the browser must print it and it creates a new page.
Therefore Im thinking that if I remove the echo statement or any other html sent back to the browser from the php code then the browser wont have to display a new page and the visitor never leaves the page they were on...unless I want them to.
Im just thinking out loud now, now that I suspect the echo statement. That why I am wondering what someone thinks of my rationale. I havent been able to get to the computer to test this yet so I wont know till tonight if Im right.
thanks for any input
If you look at your html in the first page you have an action= attribute of your form tag that SENDS you to a new page. You are the one introducing the second page and you are doing nothing to send it back to the first page. If you really MUST send yourself back to the first page, either move your php into the first page (and rename it to a php file or modify your configuration to parse html files (not a good idea)) and process it all in the first page, or use the Header command (look it up) in the second page to redirect control back to the first page.
Yeah, I didnt realize I was actually sending the browser to the php page. I thought the php page operated in the background of the server and only if I coded the php page to send back html that the html would show.
I didnt realize that when I call the php page that I actually force the browser to leave the calling page. I thought that it was like calling a function located in a different file. I thought I call the php page which executes it's code in server side background and thats all. My mistake.
Ok, then IS there a way to call server side functions (scripts, etc) that do not force me to leave the page calling the server scripts. ASP maybe?
By the way...how would I send it back to the main page...just include an href to the url maybe?
When you call anything, be it from the address bar of your browser, or from a form tag of your html, or an anchor tag, or a header command, you are sending data and control to a script or html page. If it's an html page, you are basically just asking for that page to be displayed. If it is a script (ending in .php) then the webserver (?) opens that file on your server who then sees it is a .php file and parses the php code in there and produces whatever that script is designed to do. What a php script usually does is do some input processing (using the input from the screen just seen) and then send some results back to the client, all under the guise of that script's name. There is no 'conversation' between the page you see on your screen at the time you click and anything on the server. There is simply a packet sent to the server to be handled and then another packet sent back to the client afterwards. (Generally!)
If you want to keep the scenario you have now, you will have to do what I suggested in my last post. It might involve some research on your part (as I said) but it will be good for you to read some of this stuff.
You could do your request by AJAX, which is the cleanest but more complex method.
or you could do an auto redirect from task.php once all the processing is complete, which would be simpler for a newbie.
If there is any echo, error, any output what-so-ever the following code will not work and will give an error similar to "ERROR: headers already sent".
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)