Click here to Skip to main content
15,912,273 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
querystring:
XML
<?php
echo'<html>';
echo'<body>';
$b='ascnalsnlasnlkmnaksl';
echo"<form method='post'action='querystring1.php?$b'>";
echo'<input type="text"name="txt1">';
echo'<input type="submit"name="sbm1">';
echo'</form>';
echo'</body>';
echo'</html>';
?>

querystring1:
PHP
<?php
if(isset($_POST['sbm1'])){
$a=$_POST['txt1'];
echo $a;
if(isset($_POST['b'])){
$u=$_POST['b'];
echo $u;
}
}
?>



how can i use from $b
in this page : querystring1
?????
Posted
Comments
Sergey Alexandrovich Kryukov 7-Jun-14 23:21pm    
No, not the way you are trying. This would be simple but makes no sense. If you are already using POST, why not using post data instead of URI parameters? It's much safer, better for maintenance, etc. And you are not really parametrize anything, just trying to pass a constant.
—SA

The answer would be:
Suppose your URI is "querystring1.php?key=value" then $_REQUEST['key'] would return "value", or whatever is passed as a query parameter value.

If you don't want to leverage this standard "key=value" form of passing query parameters, you have to look at the URI of the HTTP request itself and interpret it the way you wish. In particular, the whole query string can be accessed as $_SERVER['QUERY_STRING']. For related detail of URI please see, for example: http://www.phpf1.com/tutorial/get-current-page-url.html[^].

But it would not make much sense — please see my comment to the question. By the way, one widely used method of passing data via a "POST" HTTP request which is not supposed to be modified by the user is using a hidden control with the value you want to pass. The value is passed the same way you passed, for example, "txt1" value.

—SA
 
Share this answer
 
Comments
saeed rajabi 8-Jun-14 2:39am    
thanks
Mohibur Rashid 8-Jun-14 4:12am    
_REQUEST would be a bad idea. It would be better if the user use _POST, _GET OR COOKIE. and his problem can be solved in all of these methods
There are a number of way:
1. hidden field
on the querytstring.php:
$b='ascnalsnlasnlkmnaksl';
echo "<form method='post' action='querystring1.php'>";
echo '<input type="hidden" name="b" value="<?php echo $b ?>">';
echo '<input type="text" name="txt1">';
echo '<input type="submit" name="sbm1">';
echo '</input></input></input></form>';

on the querystring1.php:
$u=$_POST['b'];

2. URL parameter
on the querytstring.php:
$b='ascnalsnlasnlkmnaksl';
echo "<form method='post' action='querystring1.php?b=<?php echo $b ??>'>";
echo '<input type="text" name="txt1">';
echo '<input type="submit" name="sbm1">';
echo '</form>';

on the querystring1.php:
$u=$_GET['b'];
 
Share this answer
 
v4
Comments
saeed rajabi 8-Jun-14 2:38am    
thanks it was good
but i tried the first way means(hidden field)before
but the secend was better than frist
Peter Leow 8-Jun-14 3:54am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900