Stamatia Ch
Stamatia Ch

Reputation: 104

Passing PHP URL variables leads to Page Not Found

I have an image that is supposed to redirect to another page when it's clicked. It also "sends" two variables to the page, s and n.

echo "<a href='../?change-preference&s=up&n=".$element."'> 
         <img src='..media/images/sort-up.png'>
      </a>";

On the change-preference page I get the two variables like so:

$s=$_REQUEST['s'];
$n=$_REQUEST['n'];

My problem is that I get a "Page Not Found" error.

Also, if I try to directly access the page it works, but only if I type this:

www.example.com/preference/change-preference

and not if I try it with :

www.example.com/preference/change-preference&s=up&n=999

Any help would be appreciated!

Upvotes: 0

Views: 1283

Answers (4)

Stamatia Ch
Stamatia Ch

Reputation: 104

Well.. I didn't mention that I am working with Wordpress because I thought this was 100% PHP question. It appears that "s" is a reserved term in Wordpress causing a 404 error. Changing the "s" fixed the problem. I am living this answer here in case that some one else working on Wordpress finds him/her self in the same position. Al of the reserved terms.

Upvotes: 0

emiliopedrollo
emiliopedrollo

Reputation: 950

First you are using ? in the incorrect place as Daniel_ZA pointed out or you have typed incorrectly on your question the url that actually works. For this answer I will assume that it is the first case.

Second, do you have a php file named "change-preferences" without the .php extension? It is being parsed via php. I think probably not. So you should have a folder named change-preferences then and a file named index.php inside it right?

Well, that's the reason change-preference?s=up&n=900 redirects to change-preference\?s=up&n=900. Because you are accessing the index file for that address and not directly a file. It should work fine however.

If it still return a 404 (Page not Found) error then it's probably something that you haven't include in your question that isn't well configured or is having a bad behavior. Please try a simpler setup (create a new folder with only the minimal necessary to execute the url) or provide more information on your question.

Upvotes: 0

Daniel_ZA
Daniel_ZA

Reputation: 574

The ? is being used in the incorrect place when you are building your link.

You need to build your link as follows:

$element = 900;
echo "<a href='../change-preference?s=up&n=" . $element ."'><img src='..media/images/sort-up.png'></a>";

This will give you:

www.example.com/preference/change-preference?s=up&n=900

And in the following link from your question the ? is missing, which will not work:

www.example.com/preference/change-preference&s=up&n=999

Upvotes: 1

brtsos
brtsos

Reputation: 371

You should use:

www.example.com/preference/change-preference?s=up&n=999

Upvotes: 2

Related Questions