0

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!

Daniel_ZA
  • 574
  • 11
  • 26
Stamatia Ch
  • 104
  • 1
  • 3
  • 17
  • htaccess rewrite issue? – JustBaron Dec 21 '16 at 11:34
  • Consider using $_GET https://stackoverflow.com/questions/1924939/among-request-get-and-post-which-one-is-the-fastest#1924958 – weaveoftheride Dec 21 '16 at 11:43
  • @arkascha I tried that but when it redirects there is a `/` before the variables. `..eference/?s=up&n=999`. – Stamatia Ch Dec 21 '16 at 11:53
  • There is a difference between the two URL formats you are goving in your question. Note the difference _before_ "change-preference": `../?change-preference&s=up&n=999` != `preference/change-preference&s=up&n=999`... – arkascha Dec 21 '16 at 12:02

4 Answers4

2

You should use:

www.example.com/preference/change-preference?s=up&n=999
brtsos
  • 373
  • 3
  • 14
  • I tried to do that but the url becomes `www.example.com/preference/change-preference/?s=up&n=999` and it's againa Page not found. – Stamatia Ch Dec 21 '16 at 11:49
  • Thought so too, but look at the format of the URL used in the php code snippet, opposed to the format in the description below. – arkascha Dec 21 '16 at 12:03
  • @StamatiaCh Use you framework i.e. ZendFramework? Than check: www.example.com/preference/change-preference/s/up/n/999 – brtsos Dec 21 '16 at 12:29
1

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
Daniel_ZA
  • 574
  • 11
  • 26
0

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.

emiliopedrollo
  • 910
  • 6
  • 21
0

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.

Stamatia Ch
  • 104
  • 1
  • 3
  • 17