-2

I'm trying to get user input then make calculation based on the input.

Below is the main html. please help

<html>
    <body>
        Welcome there, <?php echo $_POST["name"]; ?>
        <br><br>
        ---- YOUR SELECTION -----
        <br><br>
    <?php
        $quantity = = echo $_POST["quantity"];
        var_dump($quantity);
        $bidprice = = echo $_POST["bidprice"];
        var_dump($bidprice);
        $total = = $quantity * $bidprice;
        var_dump($total);
    ?>
        Quantity selected: <?php echo $_POST["quantity"]; ?>
        <br>
        Bid price: <?php echo $_POST["bidprice"]; ?>
        <br> 
        Total: <?php echo $total; ?>
    </body>
</html>

Below is the form that replies based on input, but it can get the name but can't perform calculation. Why?

<html>
    <body>
        <form action="welcome_get.php" method="post">
            What is your name?
            <input type="text" name="name">
            <br><br>
            Quantity:
            <input type="number" name="quantity">
            <br>
            Bid Price:
            <input type="number" name="bidprice">
            <br>
            <input type="submit">
        </form>
    </body>
</html>
6
  • Please always add all question details to your question body via edit. Copy-paste into the question box, highlight the codeblock, then press Ctrl-K. Then delete your comments Commented Jul 6, 2018 at 3:38
  • You don't use echo to declare variable values and only one = is necessary to perform a value assignment. Commented Jul 6, 2018 at 3:40
  • Is my edit correct? $quantity = = echo $_POST["quantity"];, this is rather weird Commented Jul 6, 2018 at 3:40
  • @mickmackusa ok noted with thanks, am new to this Commented Jul 6, 2018 at 3:49
  • Here's a duplicate: stackoverflow.com/a/16876209/2943403 and stackoverflow.com/a/35138101/2943403 Commented Jul 6, 2018 at 3:52

1 Answer 1

0

You have added "= =" while assigning to variable like $quantity = = $_POST["quantity"]; This will not allow in php & you don't need to add "echo" while assigning value to variable.

Following example will help you to learn PHP Sintax

<html>
        <body>
            Welcome there, <?php echo $_POST["name"]; ?>
            <br><br>
            ---- YOUR SELECTION -----
            <br><br>
        <?php
            $quantity = $_POST["quantity"];
           $bidprice = $_POST["bidprice"];
            $total = $quantity * $bidprice;
          ?>
            Quantity selected: <?php echo $_POST["quantity"]; ?>
            <br>
            Bid price: <?php echo $_POST["bidprice"]; ?>
            <br> 
            Total: <?php echo $total; ?>
        </body>
    </html>

Output:

Welcome there, Shivrudra Samshette 

---- YOUR SELECTION ----- 

Quantity selected: 2 
Bid price: 100 
Total: 200
Sign up to request clarification or add additional context in comments.

3 Comments

wow, thank you so much, I'm a beginner thanks for helping out
@mickmackusa, i am new to stackoverflow. is it ok now?.
@JasonYeap if this code is working properly then Upvote for the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.