Jump to content

Simple Form(or so it i think)


jlaperch

Recommended Posts

I am really a novice hack but i tried researching this everywhere.

 

I just need to create a form that users enter a whole number and hit a calculate button

 

The result is the whole number *.80

 

sorry is this is waaay simple for people here...but i have been up all night trying to figure out how to write this code

 

thanks in advance

 

Link to comment
https://forums.phpfreaks.com/topic/133346-simple-formor-so-it-i-think/
Share on other sites

<?php
if (isset($_POST['sub']) && (isset($_POST['wholeNum']) && is_numeric($_POST['wholeNum']))) {
     $wholeNum = (int) $_POST['wholeNum']; // this makes sure the number is whole. could also check for decimal point
     $calculated = $wholeNum * .80;
     echo $wholeNum . " times .80 is equaled to " . $calculated . "<br /><br /> Try again?";
}
?>

<form action="index.php">
Input Whole Number: <input type="text" name="wholeNum" />
<input type="submit" name="sub" value="Calculate" />
</form>

 

Should do the trick.

http://newmilfordphoto.com/clients/index.php?wholeNum=12&sub=Calculate

 

ok here it is...am i doing something wrong...should it display the answer?

 

thanks again...i know this is probably annoying...but its a huge help to me

 

fyi...i'm trying to emulate this savings calculator on this page

 

www.ppandu.com

 

 

That was my fault, I forgot to add method inside the form tag.

 

Replace the above with this:

<?php
if (isset($_POST['sub']) && (isset($_POST['wholeNum']) && is_numeric($_POST['wholeNum']))) {
     $wholeNum = (int) $_POST['wholeNum']; // this makes sure the number is whole. could also check for decimal point
     $calculated = $wholeNum * .80;
     echo $wholeNum . " times .80 is equaled to " . $calculated . "<br /><br /> Try again?";
}
?>

<form action="index.php" method="post">
Input Whole Number: <input type="text" name="wholeNum" />
<input type="submit" name="sub" value="Calculate" />
</form>

 

That way it posts the data and not "gets"

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.