The GET method adds data to the URL

I’m using Get method to add data to the URL ,
my question is how I can get the data in URL and in the same time to be shown in the form same as using “Post”

The way this question is formed makes it very hard to understand, but if you’re asking how you can retrieve both the GET and POST data in PHP would be:

A URL of: http://sitename.com/index.php?getvar=1
with post data of

<input type='hidden' name='postvar' value='2'>

Would be retrieved in PHP with the following:

$getvar = $_GET[‘getvar’];
$postvar = $_POST[‘postvar’];

The following example will let you understand my problem,
Mainly, I need to keep the selected value as selected in the box
for example , When I select “Option3” , the url will be /testB1.asp?drop=Option3 which is fine, but the value in inbox will be returned back to “Option1”

<form action="testB1.asp?"  method="get">
<select name="drop" id="dropdown">
<option value="Option1">Option 1</option>
<option value="Option2">Option 2</option>
<option value="Option3">Option 3</option>
</select>
<input type="submit" value="Search" >
</form>

The following demo will show you more clarification about my concern
http://a.alotfy.com/Backup/0A/Demo-01.zip

Add

<form action="testB1.asp?"  method="get">
<select name="drop" id="dropdown">
<?php
if(isset($_GET['drop'])){
echo '<option value="'.$_GET['drop'].'" selected>'.$_GET['drop'].'</option>';
}
?>
<option value="Option1">Option 1</option>
<option value="Option2">Option 2</option>
<option value="Option3">Option 3</option>
</select>
<input type="submit" value="Search" >
</form>

That should do it.

after adding

<?php if(isset($_GET['drop'])){ echo ''.$_GET['drop'].''; } ?>

Still , it is showning the same issue
When I select “Option3” , the url will be /testB1.asp?drop=Option3 which is fine, but the value in inbox will be returned back to “Option1”

<?php
$options = array("Option1","Option2","Option3");
foreach($options AS $option) {
echo '<option value="'.$option.'"'.((@$_GET['drop'] == $option) ? " selected" : "").'>'.$option."</option>";
}
?>

after adding

<?php $options = array("Option1","Option2","Option3"); foreach($options AS $option) { echo ''.$option.""; } ?>

Still , it is showning the same issue
When I select “Option3” , the url will be /testB1.asp?drop=Option3 which is fine, but the value in inbox will be returned back to “Option1”

You sure you’re actually saving the page and loading it correctly? What does it show when you View Source the page the second time?

Also, this doesnt appear to be what i told you to put there. This echo as shown on the page will have no effect on the selection… did the post engine eat some of the line?

<form action="testB1.asp?"  method="get">

<select name="drop" id="dropdown">

<?php
$options = array("Option1","Option2","Option3");
foreach($options AS $option) {
echo '<option value="'.$option.'"'.((@$_GET['drop'] == $option) ? " selected" : "").'>'.$option."</option>";
}
?>

<option value="Option1">Option 1</option>
<option value="Option2">Option 2</option>
<option value="Option3">Option 3</option>

</select>
<input type="submit" value="Search3" >

</form>

see full code from the following link
http://a.alotfy.com/Backup/0A/A1.jpg

okay… you’re trying to put PHP code into an ASP page. There’s your problem.

Was just about to mention that. I thought I was going crazy.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.