Modernvox Posted November 16, 2009 Share Posted November 16, 2009 Wondering why I can't get this to display values form the form? <html> <body> <form action="getquote.php" method= "post"> Name: <input type="text" name="stories" /> Age: <input type= "text" name= "rooms" /> <input type="submit" /> </form> </body> </html> [/code [code]<html> <body> <?php if(isset($_POST['getQuote'])) $sum=$stories + $rooms; echo("$sum"); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/181681-solved-not-displaying-values/ Share on other sites More sharing options...
mikesta707 Posted November 16, 2009 Share Posted November 16, 2009 there is no form element posted with the name 'getQuotes' and there are many more errors perhaps you meant <?php if(isset($_POST['submit'])) { $storeies = $_POST['stories']; $rooms = $_POST['rooms']; $sum=$stories + $rooms; echo($sum); } ?> and change your form's submit buttons name, ie <input type="submit" name="submit" /> Quote Link to comment https://forums.phpfreaks.com/topic/181681-solved-not-displaying-values/#findComment-958225 Share on other sites More sharing options...
Modernvox Posted November 16, 2009 Author Share Posted November 16, 2009 there is no form element posted with the name 'getQuotes' and there are many more errors perhaps you meant <?php if(isset($_POST['submit'])) { $storeies = $_POST['stories']; $rooms = $_POST['rooms']; $sum=$stories + $rooms; echo($sum); } ?> and change your form's submit buttons name, ie <input type="submit" name="submit" /> From one Mike to another "Thank You". It works. Would the conditional syntax be similar to that of C++ where I want to provide a quote to the user based on there input, so I need to hold multiple values to add up? Quote Link to comment https://forums.phpfreaks.com/topic/181681-solved-not-displaying-values/#findComment-958236 Share on other sites More sharing options...
mikesta707 Posted November 16, 2009 Share Posted November 16, 2009 well, kind of. you have to store the user input in a variable as with C++, but PHP automatically stores these values in the $_POST array, so you could have simply done $sum = $_POST['stories'] + $_POST['rooms']; but i just store post variables value in local variables out of habit (and if I want to alter the values, like with trim(), mysql_real_escape_string(), etc.) I'm not sure if this answers your question, but I hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/181681-solved-not-displaying-values/#findComment-958243 Share on other sites More sharing options...
Modernvox Posted November 16, 2009 Author Share Posted November 16, 2009 well, kind of. you have to store the user input in a variable as with C++, but PHP automatically stores these values in the $_POST array, so you could have simply done $sum = $_POST['stories'] + $_POST['rooms']; but i just store post variables value in local variables out of habit (and if I want to alter the values, like with trim(), mysql_real_escape_string(), etc.) I'm not sure if this answers your question, but I hope this helps So it's not like C++ where you can just cin << response and then just cout >> when you need it. Everything is Post and Get with PHP? That is what is confusing the hell out of me. I mean I know PHP doesn't use cin and cout, but I'm just saying I need to use Post to display a value from a variable and it always needs to be done using a form? Quote Link to comment https://forums.phpfreaks.com/topic/181681-solved-not-displaying-values/#findComment-958251 Share on other sites More sharing options...
mikesta707 Posted November 16, 2009 Share Posted November 16, 2009 well thats somewhat different. cin is for input from the command line, while HTML sents http requests with POST/GET information. cin is an object (of type istream actually) and when used in conjuction with the input operator (<<) stores the input value into the variable on the right hand side. its equivalent to the function call operator<<(cin, input); the function definition looks something like istream& operator<<(istream& inputStream, string& inputValue);//for string variables When you use a form, the form sends the variables to the script itself (without having to define a variable to hold them) and server side languages can use these variables, and manipulate them as they see fit. cin is very similar to $_GET and $_POST in that you get user input, but the mechanism is slightly different Quote Link to comment https://forums.phpfreaks.com/topic/181681-solved-not-displaying-values/#findComment-958257 Share on other sites More sharing options...
Modernvox Posted November 16, 2009 Author Share Posted November 16, 2009 well thats somewhat different. cin is for input from the command line, while HTML sents http requests with POST/GET information. cin is an object (of type istream actually) and when used in conjuction with the input operator (<<) stores the input value into the variable on the right hand side. its equivalent to the function call operator<<(cin, input); the function definition looks something like istream& operator<<(istream& inputStream, string& inputValue);//for string variables When you use a form, the form sends the variables to the script itself (without having to define a variable to hold them) and server side languages can use these variables, and manipulate them as they see fit. cin is very similar to $_GET and $_POST in that you get user input, but the mechanism is slightly different I was actually looking into using command line php as it closely resembles C++ and for some reason I picked C++ language rather quickly where as PHP is puzzling me with it's syntax and Post and Get functions. I have like 4 PHP books and they have done little for me. But anyways thanks again for giving me some insight on this form stuff. Quote Link to comment https://forums.phpfreaks.com/topic/181681-solved-not-displaying-values/#findComment-958267 Share on other sites More sharing options...
mikesta707 Posted November 16, 2009 Share Posted November 16, 2009 ahh yes you can use PHP's CLI which is indeed quite similar to how cin and cout work Quote Link to comment https://forums.phpfreaks.com/topic/181681-solved-not-displaying-values/#findComment-958274 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.