Luke Harding Luke Harding - 2 months ago 12
PHP Question

Outputting HTML User Input *Using HTML Code*

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!

Answer

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";

?>