here is the code to get value from a text box and adds every digits of a number and prints total value
<html>
<body>
<form method="POST" action="adding.php">
<input type="text" name="t1" placeholder="enter a number">
<br>
<input type="submit" name="submit" value="go">
</form>
<?php
if(isset($_POST['submit']))
{
$val=$_POST['t1'];
$n=$val;
while($n!=0)
{
$rem=$n%10;
$sum+=$rem;
$quot=$n/10;
$n=$quot;
}
echo "the added value is:".$sum;
}
?>
</body>
</html>
the above code will work with no errors
No comments:
Post a Comment