Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/181681-solved-not-displaying-values/
Share on other sites

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" />

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?

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

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?

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.