sd9sd Posted July 11, 2008 Share Posted July 11, 2008 When I enter a value into the form and press enter, the php file calls itself and the form value is sent as a query string. The problem is that the query string doesn't get displayed in the addressbar. The strange thing is that when I used the same code earlier, it used to work. But ever since I've used a css file to change colour of the text, it stopped showing the query string. I don't think the css could have affected it, but I need the query string to be shown on the address bar like so: www.somesite.com/index.php?id=4 Any pointers? This is the piece of form HTML code <form name="form1" method="post" action="<TOONVALUEACTION>"> <span class="biglinks"># </span> <input name="toonValue" type="text" id="toonValue" size="6" value="<TOONVALUE>"> </form> And this is the last part of the php that replaces the TOONVALUEACTION string: if (file_exists("abc.html")) $template = implode("", file("abc.html")); //---for the php file to call itself $path = empty($_SERVER['PATH_INFO'])?$_SERVER['PHP_SELF']:$_SERVER['PATH_INFO']; $id=$_POST["toonValue"]; if ($id=="") $id=$_GET["id"]; $template = str_replace("<TOONVALUE>",$id,$template); $template = str_replace("<TOONVALUEACTION>",$path,$template); echo $template;//displays the page Quote Link to comment https://forums.phpfreaks.com/topic/114212-solved-how-to-make-the-query-string-show-up-in-the-address-bar/ Share on other sites More sharing options...
markjoe Posted July 11, 2008 Share Posted July 11, 2008 use GET method, not POST method. <form method='GET' name...> Quote Link to comment https://forums.phpfreaks.com/topic/114212-solved-how-to-make-the-query-string-show-up-in-the-address-bar/#findComment-587281 Share on other sites More sharing options...
DarkWater Posted July 11, 2008 Share Posted July 11, 2008 Use method="GET" instead. Quote Link to comment https://forums.phpfreaks.com/topic/114212-solved-how-to-make-the-query-string-show-up-in-the-address-bar/#findComment-587283 Share on other sites More sharing options...
sd9sd Posted July 11, 2008 Author Share Posted July 11, 2008 erm..that's where the problem is. When I have a GET in the html, the query string shows up in the addressbar, but the toon does not get updated (which means that the toonValue isn't captured). So I changed the $_POST["toonValue"] to $_GET["toonValue"] and now the toonValue variable is captured, but the query string isn't shown in the addressbar. Quote Link to comment https://forums.phpfreaks.com/topic/114212-solved-how-to-make-the-query-string-show-up-in-the-address-bar/#findComment-587336 Share on other sites More sharing options...
MasterACE14 Posted July 11, 2008 Share Posted July 11, 2008 you can't show it in the address bar if its a $_POST ACE Quote Link to comment https://forums.phpfreaks.com/topic/114212-solved-how-to-make-the-query-string-show-up-in-the-address-bar/#findComment-587338 Share on other sites More sharing options...
sd9sd Posted July 11, 2008 Author Share Posted July 11, 2008 but it was not showing in the addressbar when it was a $_GET. Quote Link to comment https://forums.phpfreaks.com/topic/114212-solved-how-to-make-the-query-string-show-up-in-the-address-bar/#findComment-587342 Share on other sites More sharing options...
markjoe Posted July 12, 2008 Share Posted July 12, 2008 The POST method passes the values in the headers, you will never see them in the address bar. The GET method passes the values in the URL (address bar), you will always see them in the address bar. When you access the variable, you must the corresponding name. <form method="GET"> ... $var1=$_GET['var1'] Quote Link to comment https://forums.phpfreaks.com/topic/114212-solved-how-to-make-the-query-string-show-up-in-the-address-bar/#findComment-588165 Share on other sites More sharing options...
sd9sd Posted July 21, 2008 Author Share Posted July 21, 2008 oh...got it...placing the post before the get was the problem..I'll get back after attempting a solution. Quote Link to comment https://forums.phpfreaks.com/topic/114212-solved-how-to-make-the-query-string-show-up-in-the-address-bar/#findComment-595222 Share on other sites More sharing options...
unkwntech Posted July 21, 2008 Share Posted July 21, 2008 It is possible to send both GET and POST by using method='*' so you could display the data in the address bar but still use the more secure POST method. Quote Link to comment https://forums.phpfreaks.com/topic/114212-solved-how-to-make-the-query-string-show-up-in-the-address-bar/#findComment-595233 Share on other sites More sharing options...
.josh Posted July 21, 2008 Share Posted July 21, 2008 why would you want to do that? Quote Link to comment https://forums.phpfreaks.com/topic/114212-solved-how-to-make-the-query-string-show-up-in-the-address-bar/#findComment-595239 Share on other sites More sharing options...
sd9sd Posted July 21, 2008 Author Share Posted July 21, 2008 Problem solved!!! Using GET in the form and in the PHP worked. Thanks markjoe! why would you want to do that? Lemme guess...if there are two parameters that have to be passed, and you want only one of them to be shown on the addressbar, you can receive one of them as $_GET['user'] and the other as $_POST['password'] Am I right unkwntech? Quote Link to comment https://forums.phpfreaks.com/topic/114212-solved-how-to-make-the-query-string-show-up-in-the-address-bar/#findComment-595251 Share on other sites More sharing options...
blueman378 Posted July 21, 2008 Share Posted July 21, 2008 not quite, as because it is sending ALL data through both methods both would be displayed in both sections, one possible thing is you could use it as a very cheap way to make sure the info came from your form, how many forms out there would send data to your page using both get and post, so you check to see if the $_GET value == the $_POST value, if not then in proborably didnt come from your form, not veryt secure but a possiblility Quote Link to comment https://forums.phpfreaks.com/topic/114212-solved-how-to-make-the-query-string-show-up-in-the-address-bar/#findComment-595313 Share on other sites More sharing options...
sd9sd Posted July 21, 2008 Author Share Posted July 21, 2008 that's true...it isn't secure...but nice to know that. btw, anybody knows that maximum length of a variable that can be passed in a $_POST or $GET? Quote Link to comment https://forums.phpfreaks.com/topic/114212-solved-how-to-make-the-query-string-show-up-in-the-address-bar/#findComment-595359 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.