jumpenjuhosaphat Posted January 25, 2007 Share Posted January 25, 2007 [code]$distance=$_GET['distance'];if($distance='' || !is_numeric($distance)){$distance=10000;}[/code]When I echo $distance, if I entered a number in the field, $distance comes back empty....if I entered a non-numeric string or if I don't enter anything, $distance comes back as 10000Why would that be? Link to comment https://forums.phpfreaks.com/topic/35648-get-variable-coming-up-empty-when-inserting-integers/ Share on other sites More sharing options...
Cep Posted January 25, 2007 Share Posted January 25, 2007 Can you show us the GET link you are using? Link to comment https://forums.phpfreaks.com/topic/35648-get-variable-coming-up-empty-when-inserting-integers/#findComment-168842 Share on other sites More sharing options...
suzzane2020 Posted January 25, 2007 Share Posted January 25, 2007 how are u passing te variable or value to this page..thru a form or a link.?.and does the form use GET method? Link to comment https://forums.phpfreaks.com/topic/35648-get-variable-coming-up-empty-when-inserting-integers/#findComment-168843 Share on other sites More sharing options...
jumpenjuhosaphat Posted January 25, 2007 Author Share Posted January 25, 2007 Im using a form.....[code]<form method="get" action="index.php"><input type="text" name="distance"/><input type="submit" name="submit" value="Search"</form>[/code]When I enter 295 into the form field, the URL looks like: http://www.......com/index.html?distance=295&submit=Search Link to comment https://forums.phpfreaks.com/topic/35648-get-variable-coming-up-empty-when-inserting-integers/#findComment-168844 Share on other sites More sharing options...
suzzane2020 Posted January 25, 2007 Share Posted January 25, 2007 tr usin GET instead of 'get' in the form , since u've used tht in te second page..nt sure but try Link to comment https://forums.phpfreaks.com/topic/35648-get-variable-coming-up-empty-when-inserting-integers/#findComment-168845 Share on other sites More sharing options...
jumpenjuhosaphat Posted January 25, 2007 Author Share Posted January 25, 2007 I tried that, but it gives me invalid XHTML errors when I try to validate it at W3C. It didn't make any difference here, because the get just tells the form how to pass the information, it doesn't actually assign any variable names. Link to comment https://forums.phpfreaks.com/topic/35648-get-variable-coming-up-empty-when-inserting-integers/#findComment-168847 Share on other sites More sharing options...
suzzane2020 Posted January 25, 2007 Share Posted January 25, 2007 k im nt sure if its a copy paste errorbut it isnt<input type="submit" name="submit" value="Search"i guess u've missed to close the input tag.. Link to comment https://forums.phpfreaks.com/topic/35648-get-variable-coming-up-empty-when-inserting-integers/#findComment-168851 Share on other sites More sharing options...
suzzane2020 Posted January 25, 2007 Share Posted January 25, 2007 sorry but tht wudnt make a diff anyways.. Link to comment https://forums.phpfreaks.com/topic/35648-get-variable-coming-up-empty-when-inserting-integers/#findComment-168852 Share on other sites More sharing options...
jumpenjuhosaphat Posted January 25, 2007 Author Share Posted January 25, 2007 No, plus I just typed that, it wasn't copied. The actual form is correct, I just went to make certain. It doesn't make any sense to me why when I enter a number it seems to empty the $_GET variable. Link to comment https://forums.phpfreaks.com/topic/35648-get-variable-coming-up-empty-when-inserting-integers/#findComment-168854 Share on other sites More sharing options...
Cep Posted January 25, 2007 Share Posted January 25, 2007 Your not using the GET method, get is used in links you are using POST, switch the method to post and try again with your script reading $_POST variables.Read,http://www.phpfreaks.com/phpmanual/page/language.variables.predefined.html Link to comment https://forums.phpfreaks.com/topic/35648-get-variable-coming-up-empty-when-inserting-integers/#findComment-168855 Share on other sites More sharing options...
Cep Posted January 25, 2007 Share Posted January 25, 2007 In addition,[code=php:0]<form name="myform" method="post" action="index.php"><input name="distance" type="text" /><input name="apply" type="submit" value="Search" /></form>[/code]Its a bad idea to use submit as the name of a submit button. Link to comment https://forums.phpfreaks.com/topic/35648-get-variable-coming-up-empty-when-inserting-integers/#findComment-168857 Share on other sites More sharing options...
jumpenjuhosaphat Posted January 25, 2007 Author Share Posted January 25, 2007 No, I'm using the get method. It needs to be the get method so that the pages can be bookmarked. If I use the post method, it'll hide the underlying variables and the page won't be markable.I discovered where I had gone wrong.....In the if statement, I made a big duh...:)I didn't use the double =, if(this==that), instead I used if(this=that), and by doing that, I set the value of the $distance variable to a 0. Thank you all for your help. Link to comment https://forums.phpfreaks.com/topic/35648-get-variable-coming-up-empty-when-inserting-integers/#findComment-168859 Share on other sites More sharing options...
jumpenjuhosaphat Posted January 25, 2007 Author Share Posted January 25, 2007 Just out of curiosity, why is using submit as a name bad? Is it because it's easily guessed? Link to comment https://forums.phpfreaks.com/topic/35648-get-variable-coming-up-empty-when-inserting-integers/#findComment-168861 Share on other sites More sharing options...
Cep Posted January 25, 2007 Share Posted January 25, 2007 [quote author=jumpenjuhosaphat link=topic=123969.msg513084#msg513084 date=1169722081]No, I'm using the get method. It needs to be the get method so that the pages can be bookmarked. If I use the post method, it'll hide the underlying variables and the page won't be markable.[/quote]I'm a little lost by this but if you say so. Naming a control submit causes some problems when using client side script. Link to comment https://forums.phpfreaks.com/topic/35648-get-variable-coming-up-empty-when-inserting-integers/#findComment-168864 Share on other sites More sharing options...
jumpenjuhosaphat Posted January 25, 2007 Author Share Posted January 25, 2007 [quote author=Cep link=topic=123969.msg513089#msg513089 date=1169722662][quote author=jumpenjuhosaphat link=topic=123969.msg513084#msg513084 date=1169722081]No, I'm using the get method. It needs to be the get method so that the pages can be bookmarked. If I use the post method, it'll hide the underlying variables and the page won't be markable.[/quote]I'm a little lost by this but if you say so. Naming a control submit causes some problems when using client side script.[/quote]Well, the difference between get and post is how the variables are passed to the script. In the get method, the variables are passed via the URL, in the post method, the variables are passed via the HTTP header. You can't pass variables via the post method using a link, and you can't bookmark, or save the variables using the post method. Posted variables are convenient when you don't want the values to be visible, typically for security reasons. But in my case I need the values to be part of the URL, because the site is a database driven site, and each page is a derivative of the index.php page. In other words, page 2 would be index.php?action=go&page=2Does that make sense? Thanks for the tip on the submit name, I never knew that. Link to comment https://forums.phpfreaks.com/topic/35648-get-variable-coming-up-empty-when-inserting-integers/#findComment-168870 Share on other sites More sharing options...
HuggieBear Posted January 25, 2007 Share Posted January 25, 2007 [quote author=Cep link=topic=123969.msg513089#msg513089 date=1169722662][quote author=jumpenjuhosaphat link=topic=123969.msg513084#msg513084 date=1169722081]No, I'm using the get method. It needs to be the get method so that the pages can be bookmarked. If I use the post method, it'll hide the underlying variables and the page won't be markable.[/quote]I'm a little lost by this but if you say so.[/quote]Cep,Your understanding of HTML forms is slightly off the mark. When you submit a form, you can use either the POST or the GET method. The OP clearly has GET in his/her form method and so the parameters will be passed in the URL.RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/35648-get-variable-coming-up-empty-when-inserting-integers/#findComment-168872 Share on other sites More sharing options...
Cep Posted January 25, 2007 Share Posted January 25, 2007 Aha! Your right I am a little off the mark I thought GET was strictly URL. Well you learn something new everyday as they say :D Link to comment https://forums.phpfreaks.com/topic/35648-get-variable-coming-up-empty-when-inserting-integers/#findComment-168878 Share on other sites More sharing options...
Jenk Posted January 25, 2007 Share Posted January 25, 2007 hmm.. 2 pages and no one has seen the error:This: [code=php:0]if ($distance=''[/code]should read: [code=php:0]if ($distance==''[/code]You also don't need to use the $distance=$_GET['distance']; assignment, you can just use $_GET['distance'] directly, and you should also check it exists first. Link to comment https://forums.phpfreaks.com/topic/35648-get-variable-coming-up-empty-when-inserting-integers/#findComment-168908 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.