How can i prevent connection from breaking after passing value through url to another page when user clicks back | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can i prevent connection from breaking after passing value through url to another page when user clicks back

I'm working on a project. I'm passing a variable value from a page searchusers to another page;showprofile.php via URL. Now when the user clicks the back button after viewing the showprofile.php, the browser sends a message that connection is broken or webpage isn't available. Please guys how do I fix that? Thanks for your answers.

14th Oct 2017, 8:51 AM
Ondape Valery
Ondape Valery - avatar
6 Answers
+ 5
After clicking the back button to go back to the search page where you get the error, if you click the browsers refresh button, does the page reload ok? If so, what is most likely occurring is that the browser is not only saving the location but the state of the previous page, which would actually be normal. You are most likely returning to the page with the state of being submitted. Hopefully, that makes sense. You may be able to fix this by adding some JavaScript/jQuery code that runs when the form is submitted (onsubmit="theFunction()") to change the window.location.href = url and then return true to continue with submitting the form to the action. If not, is there an error code to go along with it? Have you tried it in a different browser or 2?
14th Oct 2017, 10:41 AM
ChaoticDawg
ChaoticDawg - avatar
+ 3
I usually will create a database.php file that contains the code to connect to the database and then use something like: <?php include 'database.php';?> Towards the top of any php page that needs to have a connection to the database.
14th Oct 2017, 9:08 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
I did that bro. The problem is that when I click on back button, it shows webpage not found but when I click on the browser message, the page loads well
14th Oct 2017, 9:31 AM
Ondape Valery
Ondape Valery - avatar
+ 1
to be precise, the browser shows network error. I don't know why
14th Oct 2017, 9:35 AM
Ondape Valery
Ondape Valery - avatar
+ 1
the first page is search. php whose action is $_SERVER['PHP_SELF'] so the results are printed on the same page. then I hyperlinked the result to a custom page showprofile ie while (condition) {statement} <a href="show profile.php?id=<?php echo $id;?></a> now when the user clicks the result links, it takes them to the showprofile.php but when they click back to search something else, the browser says there's a network problem
14th Oct 2017, 9:41 AM
Ondape Valery
Ondape Valery - avatar
0
Thanks @ChaoticDawg. I'm grateful for your help. I will upload it on a server and use another device to open it. and try the other options you mentioned. And yes, the page goes back to normal when I refresh. I will try the JavaScript now
15th Oct 2017, 8:12 PM
Ondape Valery
Ondape Valery - avatar