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

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

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.