Web lists-archives.com

Re: [PHP] Calculator beginner issue




Hi Erwin,



Sent from my iPhone

> On May 8, 2016, at 2:22 PM, Erwin Noever <erwin209@xxxxxxxxx> wrote:
> 
> Hello guys,
> 
> I am sorry to disturb you.
> 
> I followed a tutorial and i am a newbe to php but want to learn.
> 
> My calculator doesn't work, i dont see what is wrong.
> Please can someone explain what the issue is or give me a hint.
> Thank you in advance.
> Html Code:
> 
> <form method="post" action="calc.php">
>    <input type="text" name="nummer1" placeholder="nummer1" />
>    <label for="kies">kies</label>
>    <select name="reken" id="kies">
>        <option>selecteer</option>
>        <option value ="plus">+</option>
>        <option value ="min">-</option>
>        <option value ="delen">÷</option>
>        <option value ="maal">x</option>
>    </select>
>    <input type="number" name="nummer2" placeholder="nummer2" />
>    <input type="submit" value="calculeer" />
> 
> </form>
> 
> php code:
> 
> function bereken ()
> {
>    $nummer1 = $_POST['nummer1'];
>    $nummer2 = $_POST['nummer2'];
> 
>    switch ($_POST['reken'])
>    {
>        case "plus":
>            $plus = $nummer1 + $nummer2;
>            return $plus;
>        break;
> 
>        case "min":
>            $min = $nummer1 - $nummer2;
>            return $min;
>            break;
> 
>        case "delen":
>            $deel = $nummer1 / $nummer2;
>            return $deel;
>            break;
> 
>        case "maal":
>            $maal = $nummer1 * $nummer2;
>            return $maal;
>            break;
>        default:
>            echo "bereken op een andere maniet";
>    }
> }
> 
>    echo "het resultaat is :". bereken();
> 
> ?>
> <br>
> <a href="index.html">terug</a>

I would throw in a few echos on the variables to make sure it's what you're expecting. 

<?php

Echo "bummer 1: " . $nummer 1;

?>

That way you can validate that you at least have the right info. And also sanitize your input :)

Thanks!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php