PDA

View Full Version : Set more variables to URL



Earliboy
30th January 2013, 01:05
Hello,
I'm currently editing a php script. The current URL is /file.php?id=2. I got an form which sets limit_rows so after refresh the url should look like /file.php?id=2&limit_rows=500
May its cause I'm too tired but what i get out of this is /?&limit_rows=500.

May you find whats wrong or what i forgot to add.



?>
<center>
<h5>Enter number of lines you want to see.</h5>
<table>
<form action="&" method="get">
<input type="text" name="limit_rows" />
<br/>
<input type="submit" value="Refresh" />
</form>
</table>
</center>
<br>
<?php
echo isset($_GET['limit_rows']) ? htmlspecialchars($_GET['limit_rows']) : '';


And no, the ?> isnt wrong, i just don't wanna copy&paste a 2k line script ^^.

Thanks for help.
Earli.

kung foo man
30th January 2013, 01:14
<form action="<?=$_SERVER["REQUEST_URI"]?>" method="get">


That should already do the trick (because its writing the old GET-parameters into the form-address).

Earliboy
30th January 2013, 01:16
Doesnt works, it redirects me to a different page (may cause some includings).

kung foo man
30th January 2013, 01:24
Can you look in the source-code and write here what PHP added to the formular? It shouldn't be possible that it directs you to another page (maybe Echelon is doing it on missing parameters).

Earliboy
30th January 2013, 01:28
<form action="/echelon/clientdetails.php?id=2" method="get">
<input type="text" name="limit_rows" />
<br/>
<input type="submit" value="Refresh" />
</form>


But i get redirected to clients.php

kung foo man
30th January 2013, 01:38
Does it also redirects you to clients.php if you type the url (/echelon/clientdetails.php?id=2) directly into the browser? :confused:

Earliboy
30th January 2013, 01:39
If i type in /clientdetails?id=2&limit_rows=500 it shows 500 rows and also show up the standart value in the text box (500). So the limit_rows define when i type in by myself.

Earliboy
30th January 2013, 03:34
Well okay, i made some changes and the problem is may the overgiving of the URL.
Yes, i messed the code a littlebit up but i get my outputs that tells me that everything should be allright.


$newURL = $_SERVER["REQUEST_URI"];
echo $newURL;

$_GET['limit_rows'] = 500;

Sets the actualy URL and output it, also sets the limit rows to 500 (to test)
Output:


/echelon/clientdetails.php?id=2

next parts:


$newURL .= "&limit_rows=".$_GET['limit_rows'];

echo $newURL;
echo "<br>";

if(isset($_GET['limit_rows']))
{
$newURL .= "&limit_rows=".$_GET['limit_rows'];

echo isset($newURL) ? htmlspecialchars($newURL) : '';
}

Outputs:

/echelon/clientdetails.php?id=2&limit_rows=500
/echelon/clientdetails.php?id=2&limit_rows=500&limit_rows=500
Even the second line works fine if i set it manually to the url.

Actually Form:


<center>
<h5>Enter number of lines you want to see.</h5>
<!--<form action="<?//=$_SERVER["REQUEST_URI"]?>" method="get">-->
<form action="<?php $newURL ?>" method="get">
<input type="text" name="limit_rows" value="<?php echo $limit_rows?>" onblur="if(this.value == ''){ this.value = '<?php echo $limit_rows?>'; }" onfocus="if(this.value == '<?php echo $limit_rows?>'){ this.value = '';}" />
<br/>
<input type="submit" value="Refresh" />
</form>
</center>
<br>


So the URL is fine, the overgive of the URL should be fine, the old one should output the same. Idk whats wrong at here, i still get redirected to clients.php if i click on the refresh button.

Any ideas?

And btw, I'm working now 3 hours on this error ^^