Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Multiplication Script 1

Status
Not open for further replies.

Tubby6

Technical User
Jun 4, 2007
26
CH
hello,

im trying to find the product of two numbers that i input.
but it does not work? am i setting the variables incorrectly?
can anyone please help?
your help is greatly appreciated
eliana


<form method="get" action="process.php">
<h2>Evaluate Costs for Programs! </h2>
insurance_cost: <input type="INT" name="insurance_cost"><br>
Days abroad: <input type="INT" name="days"><br>
<input type="Submit" name="submit" value="Search">
<input type="Submit" name="reset" Value="Reset">
</form>

<?php

$cost = '$insurance_cost';
$day = '$days';
$premium = $cost * $day;
$result=
echo "My Insurance Cost is =" .$income;
?>


 
Unless, and this s a big unless, your PHP installation is set to have register globals on then you should be addressing your form variables $_GET['nameofvariable'];





----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
hello again,
i redid the code using get as the variables are most likely not global but it just does not work. im receiving an error?
can anyone help?
thank you vacunita for your help
best
tubby6

<html>
<form method="get" action="process.php">
<h2>Evaluate Costs for Programs! </h2>
insurancecost: <input type="INT" name="insurancecost"><br>
Daysabroad: <input type="INT" name="days"><br>
<input type="Submit" name="submit" value="Search">
<input type="Submit" name="reset" Value="Reset">
</form>

<?php

$cost = '$_GET['insurancecost'];
$day = '$_GET['Daysabroad'];
$premium = $cost * $day;
echo "My Insurance Cost is =" . $_GET['premium'];
?>
 
1. You have a leading "'" in front of the first two $_GETs. That's your syntax error.
2. One of your $_GET variable names doesn't match your form.
3. $premium is not being passed via $_GET.
 
I said Form variables not all your variables. As in just the ones coming from your form. In addition to the errors pointed out by lgarner.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
im sorry again..
but it seems as even though i alter the code to fix the mistakes the form is still not evaluating..

i5.nyu.edu/~lia205/process.php

thank you
eliana

<html>
<form method="get" action="process.php">
<h2>Evaluate Costs for Programs! </h2>
insurancecost: <input type="INT" name="insurancecost"><br>
Daysabroad: <input type="INT" name="days"><br>
<input type="Submit" name="submit" value="Search">
<input type="Submit" name="reset" Value="Reset">
</form>

<?php

$cost = $_GET['insurancecost'];
$day = $_GET['days'];
$premium = $_GET['$cost * $days'];
echo "My Insurance Cost is =" . $_GET['$premium'];
?>
 

ive tried other variations as well and it doesnt seem to work.. can anyone please help me out.
its so frustrating :(
<html>
<form method="get" action="process.php">
<h2>Evaluate Costs for Programs! </h2>
insurancecost:<input type="INT" name="insurancecost"><br>
days:<input type="INT" name="days"><br>
<input type="Submit" name="submit" value="Search">
<input type="Submit" name="reset" Value="Reset">
</form>

<?php

$insuranctcost= $_GET['insurancecost'];
$days= $_GET['days'];
$premium = $_GET['$insurancecost * $days'];
echo "My Insurance Cost is =" . $premium;
?>
 
<html>
<form method="get" action="process.php">
<h2>Evaluate Costs for Programs! </h2>
insurancecost:<input type="INT" name="insurancecost"><br>
days:<input type="INT" name="days"><br>
<input type="Submit" name="submit" value="Search">
<input type="Submit" name="reset" Value="Reset">
</form>

<?php

$insurancecost= $_GET['insurancecost'];
$days= $_GET['days'];
$premium = $_GET['$insurancecost * $days'];
echo "My Approximate Insurance Cost is =" . $_GET['$premium'];
?>
 
hello
i read a bit about the get method.
ive fixed all possible syntax errors. however, i still am not able to get an actual result.
can anyone please help?
your help is greatly appreciate

<html>
<form method="get" action="process.php">
<h2>Evaluate Costs for Programs! </h2>
insurancecost:<input type="INT" name="insurancecost"><br>
days:<input type="INT" name="days"><br>
<input type="Submit" name="submit" value="Search">
<input type="Submit" name="reset" Value="Reset">
</form>

<?php

$insurancecost= $_GET['insurancecost'];
$days= $_GET['days'];
$premium = '$insurancecost * $days';
echo "My Approximate Insurance Cost is =" . $_GET['$premium'];
?>
 
Well, you still have quotes around your equation. And you're still trying to read an HTTP GET variable called 'premium', which I don't see defined anywhere.
 

SUCCESS
THANK YOU FOR YOUR HELP

<html>
<form method="get" action="process.php">
<h2>Evaluate Costs for Programs! </h2>
insurancecost:<input type="INT" name="insurancecost"><br>
days:<input type="INT" name="days"><br>
<input type="Submit" name="submit" value="Search">
<input type="Submit" name="reset" Value="Reset">
</form>

<?php

$insurancecost= $_GET['insurancecost'];
$days= $_GET['days'];
$premium = $insurancecost * $days;
print "Approximate Insurance Cost is" . $premium . "<br>";

?>
 
In addition to all this, you were very lucky that your browser tolerated you. There is no INT type for the input element. A stricter browser might get confused as to what you want and not submit the values at all.

The type you would want is text, as in:
Code:
<input type="text" name="days" />

However, as a first step, I would suggest reading up on a couple php and html tutorials. You demonstrate a lack of understanding of the whole subject.

___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top