2

I am trying to output information that the user inputs into the website. Here is my code for the first part of the page that displays the information that is filled in (this code works):

<form action = "comment_process.php" method = "post">
    Name: 
    <input type = "text" name = "name"/> <br>

    Do you like this page?
    <input type = "radio" name = "answer" value = "Yes"> Yes 
    <input type = "radio" name = "answer" value = "No"> No <br>

    Comment:
    <textarea rows="3" cols="50" name = "comment"/> </textarea> <br>

    Rating 
    <select name = "rating"> <br>
        <option value = "0"> 1 </option>
        <option value = "1"> 2 </option>
        <option value = "2"> 3 </option>
        <option value = "3"> 4 </option>
        <option value = "4"> 5 </option> 

    <input type = "submit" value = "go"/>
</form>

However, the page that processes the entered data does not work. My code for that is below:

<?php

    $v = $_POST['firstname'];
    $x = $_POST['comment'];
    $y = $_POST['answer'];
    $z = $_POST['rating'];

    echo "Hello $v! <br>"

    if ($y == "Yes") {

        echo "I am happy that you like the page :)"

    }
    else {

        echo "I am sorry that you do not like the page :("

    }

    echo "Thanks for your comment [$x]";
    echo "You rated our page as Rating $z";

?>

I am trying to output what is in the small text boxes on the right side of the screen based on the data entered by the user:

enter image description here

I was wondering if someone could please help me!

Luke Harding
  • 105
  • 2
  • 2
  • 9
  • But this is using HTML code, I couldn't really understand the other code too well – Luke Harding Oct 05 '16 at 01:18
  • I updated my processing page code, but it still does not work – Luke Harding Oct 05 '16 at 01:34
  • You have to understand that HTML is barely interactive. You must use JavaScript handle events and do ajax with POST request. Then, you have to retrieve data of response and update the element of HTML the text box you said. Anyway, there are a lot resources could be found on the Internet and I remind you search it first.... – Anson Oct 05 '16 at 01:38
  • Every php line should end with `;` - check your echo statements – Onimusha Oct 05 '16 at 01:48
  • ^, the first three echo's are missing semi colons. – Perspective Oct 05 '16 at 01:50

2 Answers2

0

Check your input naming. It is name in your HTML and firstname in your php. Also make sure to use a semi-colon after each line in your php or else it will have errors. echo "Hello $v! <br>";

Not an error, but maybe confusing, your options in the drop down have different values than the use might expect <option value = "0"> 1 </option>. This will mean they are told they rated 0 when they rated 1. Also means your if will include ratings 3 or lower in the sorry option.


Edit: with your edited code, the first echo line in your php will cause an error due to no semicolon.

Luke
  • 640
  • 3
  • 10
0

you had some mistakes in it

this worked for me:

<form action = "comment_process.php" method = "post">
    Name: 
    <input type = "text" name = "name"/> <br>

    Do you like this page?
    <input type = "radio" name = "answer" value = "Yes"> Yes 
    <input type = "radio" name = "answer" value = "No"> No <br>

    Comment:
    <textarea rows="3" cols="50" name = "comment"/> </textarea> <br>

    Rating 
    <select name = "rating"> <br>
        <option value = "0"> 1 </option>
        <option value = "1"> 2 </option>
        <option value = "2"> 3 </option>
        <option value = "3"> 4 </option>
        <option value = "4"> 5 </option> 

    <input type = "submit" value = "go"/>
</form>


<?php

    $v = $_POST['firstname'];
    $x = $_POST['comment'];
    $y = $_POST['answer'];
    $z = $_POST['rating'];

    echo "Hello $v";

    if ($y == "Yes") {

        echo "I am happy that you like the page :)";

    }
    elseif ($y == "No") {

        echo "I am sorry that you do not like the page :(";

    }

    echo "Thanks for your comment [$x]";
    echo "You rated our page as Rating $z";

?>
Herrsocke
  • 272
  • 4
  • 13
  • This worked perfectly! Thank you! I think I was just missing some semi-colons and had some other stuff I missed. Thanks again – Luke Harding Oct 05 '16 at 01:52