Adding using HTML forms and PHP

2013 年 3 月 6 日4990

<?php



// Get data from HTML form.



$addScore1 = $_POST['addScore1'];



$addScore2 = $_POST['addScore2'];



$oldScore1 = $_POST['oldScore1'];



$oldScore2 = $_POST['oldScore2'];







$newScore1 = (int) $oldScore1 + (int) $addScore1;



$newScore2 = (int) $oldScore2 + (int) $addScore2;



?>



<h2>Old Sores</h2>



<p>



<input type="text" value="<?=$oldScore1?>">



<input type="text" value="<?=$oldScore2?>">



</p>



<h2>New Sores</h2>



<p>



<input type="text" value="<?=$newScore1 ?>">



<input type="text" value="<?=$newScore1 ?>">



</p>



Is this what you need?

UPDATE:

Try this code:

Just tested it works as a calculator :) Hope thats what you need.

<?php



// Get data from HTML form.



$addScore1 = (int) $_POST['addScore1'];



$addScore2 = (int) $_POST['addScore2'];







$oldScore1 = (int) $_POST['newScore1'];



$oldScore2 = (int) $_POST['newScore2'];







$newScore1 = (int) $oldScore1 + (int) $addScore1;



$newScore2 = (int) $oldScore2 + (int) $addScore2;







?>



<html>



<head>



<title>Score Add</title>



</head>







<body>



<form method="post" action="">



<h2>Old Scores</h2>



<p>



<input type="text" value="<?=$oldScore1?>">



<input type="text" value="<?=$oldScore2?>">



</p>



<h2>New Scores</h2>



<p>



<input type="text" value="<?=$newScore1 ?>">



<input type="text" value="<?=$newScore2 ?>">



</p>



<h2>Add Scores</h2>



<p>



<input type="text" value="">



<input type="text" value="">



</p>



<input type="submit" />



</form>



</body>



</html>



0 0