WebCheez Posted May 14, 2011 Share Posted May 14, 2011 The following block of code won't work. $prob = $prob + 1; $_SESSION['prob']=$prob; header( 'Location: question' . $prob . '.php' ); This is just a small part of my script. I've made sure using print that $prob is 1 and is changed to 2. HOWEVER it gives me an error 404 page at question3, not question2. I'm trying to make a quiz system. Quote Link to comment https://forums.phpfreaks.com/topic/236394-header-glitch-or-is-it/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 14, 2011 Share Posted May 14, 2011 Using a series of pages named question1.php, question2.php, question3.php,... would be the hardest way of doing this because you are not making use of what php was designed for - letting php dynamically produce the web pages instead of you creating the web pages by hand. You should be using a GET parameter on the end of the URL that indicates what action your single page of code does - index.php?question=1 index.php?question=2 index.php?question=x $_GET['question'] would have the value x when the page is requested. As to your 404 error for the question3.php page, obviously you don't have a page in the current location by that exact name. Did you look at the file, checking for things like spelling errors and if you created your file using a Windows supplied editor, are you sure your file does not have a hidden .txt extension? Quote Link to comment https://forums.phpfreaks.com/topic/236394-header-glitch-or-is-it/#findComment-1215329 Share on other sites More sharing options...
WebCheez Posted May 14, 2011 Author Share Posted May 14, 2011 Using a series of pages named question1.php, question2.php, question3.php,... would be the hardest way of doing this because you are not making use of what php was designed for - letting php dynamically produce the web pages instead of you creating the web pages by hand. How else would I do this? I do need all of the radio button options, and the question itself. MySQL? As to your 404 error for the question3.php page, obviously you don't have a page in the current location by that exact name. Did you look at the file, checking for things like spelling errors and if you created your file using a Windows supplied editor, are you sure your file does not have a hidden .txt extension? It's trying to redirect to the wrong page, it's supposed to be redirecting to question2.php. And yes. Quote Link to comment https://forums.phpfreaks.com/topic/236394-header-glitch-or-is-it/#findComment-1215523 Share on other sites More sharing options...
PFMaBiSmAd Posted May 14, 2011 Share Posted May 14, 2011 The code probably is redirecting to question2.php but the code on question2.php is probably redirecting to quesiton3.php due to an error in your logic or your browser is requesting question1.php twice and is using the content of the session variable + 1 to redirect to quesiton3.php What is the whole code on the quesiton1.php and question2.php pages? How else would I do this? ^^^ I showed how you would use a GET parameter on the end of the URL for one page to provide a value to the code on that page that would be used to determine what action that page takes. You would typically use a database to hold the content for dynamically produces php pages and just query for the correct content to be displayed. Quote Link to comment https://forums.phpfreaks.com/topic/236394-header-glitch-or-is-it/#findComment-1215534 Share on other sites More sharing options...
WebCheez Posted May 15, 2011 Author Share Posted May 15, 2011 Oh, woops, I fixed it. Looks like I'll have to redefine my method of telling if the previous question was correct. Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/236394-header-glitch-or-is-it/#findComment-1215795 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.