Jump to content

helen11

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

helen11's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. It won't work for me and i'm ready to pull my hair out
  2. Ok thanks for that I have only one form element now. Do you know how i would post the selected radio button to the backend php program?
  3. I'm not talking about the calculation text boxes that part works, when 5 numbers are put in the text boxes and calculated it returns the answer. What I want to know is how do I get the chosen radio button option posted to the backend php program?
  4. I would like the radio button option from a html form posted to a backend php program along with a simple calculation, I can get the calculator to work but I cant get it to post the radio button value. Any help would be greatly appreciated. <head> <title></title> </head> <body> <h1>Simple Calculator</h1> <h2>Please Select an Option</h2> <form method="post" action="calculation.php"> <div> <input type="radio" name="calcu" value="Highest"> Highest<br> <input type="radio" name="calcu" value="Lowest" checked> Lowest<br> <input type="radio" name="calcu" value="Average"> Average<br> <input type="radio" name="calcu" value="Sort in ascending order"> Sort in ascending order<br> </div> </form> <h2>Insert five numbers in the form and hit submit button</h2> <form method="post" action="calculation.php"> <p>Value 1: <input type="text" name="val1" size="10"></p> <p>Value 2: <input type="text" name="val2" size="10"></p> <p>Value 3: <input type="text" name="val3" size="10"></p> <p>Value 4: <input type="text" name="val4" size="10"></p> <p>Value 5: <input type="text" name="val5" size="10"></p> <p>Calculation:<br> <input type="radio" name="calc" value="add"> add<br> <input type="radio" name="calc" value="subtract"> subtract<br> <input type="radio" name="calc" value="multiply"> multiply<br> <input type="radio" name="calc" value="divide"> divide</p> <p><input type="submit" name="submit" value="Calculate"></p> </form> </body> </html> <head> <title>Simple Calculator</tite> </head> <body> <?php if (($_POST[val1] == "") || ($_POST[val2] == "") || ($_POST[val3] == "") || ($_POST[val4] == "") || ($_POST[val5] == "") || ($_POST[calc] =="")) { header("Location: form.html"); exit; } if ($_POST[calc] == "add") { $result = $_POST[val1] + $_POST[val2] + $_POST[val3] + $_POST[val4] + $_POST[val5]; } else if ($_POST[calc] == "subtract") { $result = $_POST[val1] - $_POST[val2] - $_POST[val3] - $_POST[val4] - $_POST[val5]; } else if ($_POST[calc] == "multiply") { $result = $_POST[val1] * $_POST[val2] * $_POST[val3] * $_POST[val4] * $_POST[val5]; } else if ($_POST[calc] == "divide") { $result = $_POST[val1] / $_POST[val2] / $_POST[val3] / $_POST[val4] / $_POST[val5]; } echo "<title>Calculation Result</title>"; echo "<p>The result of the calculation is: $result</p>"; echo "<p><a href=\"form.html\" target=\"_self\">Do Another</a></p>"; ?> </body> </html>
  5. Hi I am trying to make a php calculator with radio buttons to choose options and plus 5 textboxes for entry of any 5 numbers. The numbers entered into the textboxes and thee radio button option should to be posted to a backend php program but I can't get it to work. If anyone can offer some help it would be greatly appreciated as i'm new to php and am having great difficulty getting my head around it. My code is: <h1>Simple Calculator</h1> <form name="myform" action="calculation.php" method="POST"> <h2>Please Select an Option</h2> <div> <input type="radio" name="calculator" value="Highest"> Highest<br> <input type="radio" name="calculator" value="Lowest" checked> Lowest<br> <input type="radio" name="calculator" value="Average"> Average<br> <input type="radio" name="calculator" value="Sort in ascending order"> Sort in ascending order<br> </div> </form> <h2>Insert five numbers in the form and hit submit button</h2> <form action="calculation.php" method="post"> Enter First No. <input type="text" name="firstnum"> Select operator: <select name="operator"> <option>+</option> <option>-</option> <option>*</option> <option>/</option> </select> Enter Second No. <input type="text" name="secondnum"> Select operator: <select name="operator"> <option>+</option> <option>-</option> <option>*</option> <option>/</option> </select> Enter Third No. <input type="text" name="thirdnum"> Select operator: <select name="operator"> <option>+</option> <option>-</option> <option>*</option> <option>/</option> </select> Enter Fourth No. <input type="text" name="fourthnum"> Select operator: <select name="operator"> <option>+</option> <option>-</option> <option>*</option> <option>/</option> </select> Enter Fith No. <input type="text" name="fithdnum"> <input type="submit" name="calculate" value="Calculate"> </form> </body> </html> My php: </head> <body> <?php $first=$_POST['firstnum']; $second=$_POST['secondnum']; $third=$_POST['thirdnum']; $fourth=$_POST['fourthnum']; $fith=$_POST['fithnum']; $operator=$_POST['operator']; if ($operator=="+") {$total=$first + $second + $third + $fourth + $fith;} if ($operator=="-") {$total=$first - $second - $third - $fourth - $fith;} if ($operator=="*") {$total=$first * $second * $third * $fourth * $fith;} if ($operator=="/") {$total=$first / $second / $third / $fourth / $fith;} echo $total; ?> </body> </html> Thanks in advance.
  6. Because i've been told to use a 2d array. It still won't work i'm ready to pull my hair out.
  7. That doesn't seem to work this is what I need to do: Use two separate for loops to roll a dice 26 times and assign each result in turn along with its roll number to a two dimensional array in the first for loop then count the total value of dice rolls over 26 throws and print to an html table with a header row using a second program loop. The total value of the dice rolls plus the average value per throw should be printed out. This is what I have: <?php $aRolls = array(); $rolls = 26; $sides = 6; for ($i = 0; $i < $rolls; ++$i) { $aRolls[] = rand(1, $sides); } $aValueCount = array_count_values($aRolls); print '<table><tr><th>Roll Number</th><th>Roll Value</th></tr>'; for($i=1; $i <= $sides; ++$i) { printf('<tr><td>%d</td><td>%d</td></tr>', $i, $aValueCount[$i]); } print '</table>'; ?>
  8. HI I have put together a php script that rolls a dice 26 times and assigns each result in turn along with its roll number. What I want to do now is print the total roll value and the average roll value but as i'm new to php I dont know how to do this so any help would be greatly appreciated. This is what I have so far <head> <title>Dice Roll</title></head> <body> <?php $rolls = 26; $sides = 6; $results = array_fill(1, $sides, 0); for($i=1; $i<=$rolls; $i+=1) { $roll = rand(1, $sides); $results[$roll] += 1; } print '<table><tr><th>Roll Number</th><th>Roll Value</th></tr>'; for($i=1; $i<=$sides; $i+=1) { printf('<tr><td>%d</td><td>%d</td></tr>', $i, $results[$i]); } print '</table>'; ?> </body> </html>
×
×
  • 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.