jlaperch Posted November 19, 2008 Share Posted November 19, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/133346-simple-formor-so-it-i-think/ Share on other sites More sharing options...
premiso Posted November 19, 2008 Share Posted November 19, 2008 <?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. Quote Link to comment https://forums.phpfreaks.com/topic/133346-simple-formor-so-it-i-think/#findComment-693505 Share on other sites More sharing options...
jlaperch Posted November 19, 2008 Author Share Posted November 19, 2008 awesome thanks... so do i put that in 2 separate files...really need hand holding here... what should i name the files? thanks john p.s. love the family guy reference on your profile tag Quote Link to comment https://forums.phpfreaks.com/topic/133346-simple-formor-so-it-i-think/#findComment-693517 Share on other sites More sharing options...
premiso Posted November 19, 2008 Share Posted November 19, 2008 One file called "index.php" and that will work like a champ. Quote Link to comment https://forums.phpfreaks.com/topic/133346-simple-formor-so-it-i-think/#findComment-693526 Share on other sites More sharing options...
jlaperch Posted November 19, 2008 Author Share Posted November 19, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/133346-simple-formor-so-it-i-think/#findComment-693560 Share on other sites More sharing options...
premiso Posted November 19, 2008 Share Posted November 19, 2008 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" Quote Link to comment https://forums.phpfreaks.com/topic/133346-simple-formor-so-it-i-think/#findComment-693568 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.