0

I think the question is a bit confusing but technically I am passing a value from one page :

<a href="Admin-updateGamesFunctions.php?gameID=<?php echo $file['gameID'];?>">Update</a>

As you can see when I click the link "Update" I will be redirect to the next page (Admin-updateGamesFunctions.php) while passing the value gameID. I'm receiving the value by using :

if(isset($_GET['gameID']))
{
$updateGame = $_GET['gameID'];
}

Now everything about the page works perfectly. However, when I'm done submitting the form I try to redirect back to the same page while retaining the gameID I got from previous page. This here is my current code for that :

header(" location : Admin-updateGamesFunctions.php?gameID=".$updateGame);

However when it redirects all I got is :

Server error! The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.

P/S : Not sure if this is needed but I'm avoiding including the previous page due to reasons.

Edit :

Doing what @Felix Mellitzer said does help in removing the error. (Need to remove the header first) Anyway the reason I'm trying to retain the gameID is because I'm using echo at the page that shows all the attributes of the object (games) based on its gameID. So I was hoping that after I done submitting the form (which updates the attributes of the game) it will also update the data echoed on the page. However the data echoed on the page is not updated.

Edit 2 : I already found out how to update the echoed data. Just use

header("Refresh:0");

Thanks everyone!

HaziqKha17
  • 15
  • 3
  • "I will be redirect"...FYI technically that's just navigating to a new URL via a hyperlink. A redirect is slightly different (i.e. when the server tells the browser to go to a different URL, rather than the user initiating it directly) - your use of the "Location" header would create a redirect instruction, for example. – ADyson Dec 12 '19 at 10:54
  • Anyway regarding your error. Do you have error reporting or logging enabled for PHP? That error message sounds very generic and you probably need to discover the real underlying cause, which is quite likely to have been the result of a PHP exception of some sort. This can help you set it up: https://stackoverflow.com/questions/845021/how-can-i-get-useful-error-messages-in-php. Once you've got logging or reporting enabled, see if you can see a specific exception message in relation to this issue. – ADyson Dec 12 '19 at 10:57
  • 1
    are you getting loop error ? – OMi Shah Dec 12 '19 at 10:59
  • I don't understand why you need `header(" location : Admin-updateGamesFunctions.php?gameID=".$updateGame);` – Nova Dec 12 '19 at 11:44
  • Thanks @ADyson for the information – HaziqKha17 Dec 12 '19 at 12:43
  • @OMiShah I'm not sure, the error message only says Server error – HaziqKha17 Dec 12 '19 at 12:44
  • @ChengHuiYuan I thought that by doing that it will retain the value of gameID but since I'm getting an error I'm guessing it is wrong – HaziqKha17 Dec 12 '19 at 12:47

2 Answers2

2

When you submit the form, the $_GET['gameID'] is lost. Change your form URL to include the gameID.

Example:

<form action="/action_page.php?gameID=<%= $_GET['gameID'] %>">
  ...

However as @Ajeenckya already said. You should use something like the session. By using sessions, you don't have to pass the parameters all the time.

  • I disagree about using sessions for specific data items such as this. Session should be for something which lasts the lifetime of the session and is always applicable (e.g. current username, user preferences, things like that), not a variable to retrieve a specific data item on a specific instance of a specific page. If you use session for this, it effectively stops the user having different records open in different tabs, which will annoy a lot of people – ADyson Dec 12 '19 at 11:34
  • Thanks Felix, by doing what you said I manage to get rid of the error (The header must be remove first) and I do try to avoid sessions for reasons as stated by @ADyson. – HaziqKha17 Dec 12 '19 at 13:05
0

Try using PHP sessions $_SESSION for managing data across pages in PHP. https://www.php.net/manual/en/reserved.variables.session.php

Ajeenckya
  • 19
  • 3
  • Not good if the user has more than one table open of the same page. People do that all the time. Sessions have their uses, but I don't think this is a good use of it. – ADyson Dec 12 '19 at 10:58