j.smith1981 Posted October 20, 2010 Share Posted October 20, 2010 I was wondering just a general question here. I am just going through a text book on the main aspects of a problem solving approach to PHP, but when I was just trying out one of my own theories on this particular one of my own: <html> <body> <h1>User Input set as functions</h1> <tt>Please enter a value below:</tt> <br> <form id="userInput" name="userInput" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get"> <input type="text" id="input" name="input" value="" /> <input type="submit" value="Send This" /> </form> <?php function mistake($errorvalue) { echo $errorvalue; } function getValue($userInput) { return $userInput; } if(!isset($_GET['input']) || $_GET['input'] == '') { mistake("No value received yet!"); // calls the error function } else { $input = $_GET['input']; echo "You did enter something, this was: "; $userInput = getValue($input); echo "$userInput"; } ?> </body> </html> I am quite impressed with what I have done there, though I know its nothing special and could obviously be done not using functions at all, just wanted to see if I could get one that returns something, in this case the 'getValue()' function. But when I've set it to work out what type of variable ie gettype is it? (going off completely memory here), its always a string, even if all I do is enter a 1, even tried not using the GET method for the form and used the POST one instead it still says that a single integer is a string. Why just out of question is it doing this? Just quite interested thats all. Thanks for your time and I look forward to any replies, Jeremy. Quote Link to comment https://forums.phpfreaks.com/topic/216380-getting-a-datatype-from-a-form-submission-one-user-input-only/ Share on other sites More sharing options...
The Little Guy Posted October 20, 2010 Share Posted October 20, 2010 A form always sets the GET/POST type to a string. So. No matter what you will always get a string. You may want to take a look at the ctype functions. Quote Link to comment https://forums.phpfreaks.com/topic/216380-getting-a-datatype-from-a-form-submission-one-user-input-only/#findComment-1124429 Share on other sites More sharing options...
PFMaBiSmAd Posted October 20, 2010 Share Posted October 20, 2010 By definition (it's mentioned somewhere in the php.net documentation) all $_GET, $_POST, and $_COOKIE variables are string data types, no matter what they contain. You should instead be more concerned with the value in the variable, than the type of the variable. See the is_numeric function to determine if the value in a variable is numeric. Quote Link to comment https://forums.phpfreaks.com/topic/216380-getting-a-datatype-from-a-form-submission-one-user-input-only/#findComment-1124430 Share on other sites More sharing options...
j.smith1981 Posted October 20, 2010 Author Share Posted October 20, 2010 By definition (it's mentioned somewhere in the php.net documentation) all $_GET, $_POST, and $_COOKIE variables are string data types, no matter what they contain. You should instead be more concerned with the value in the variable, than the type of the variable. See the is_numeric function to determine if the value in a variable is numeric. Ah ok thats cool, just not really using this of course for productional purposes more a prove to myself I could get it to return a value that's all, for educational purposes myself. Thanks for your help though as always much appreciated! Jeremy Quote Link to comment https://forums.phpfreaks.com/topic/216380-getting-a-datatype-from-a-form-submission-one-user-input-only/#findComment-1124444 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.