I'm very new to coding, total noob, and I'm trying to print out a text based on grades. Like if they choose 1, then print "Bad", etc. I'm thinking I could use if/else, but I'm so new to coding I don't know. I've been googling, but I just dont know who to get the form and the text to work together. Can anyone help please?
<section class="evaluation">
<h2>Test</h2>
<p>More info here</p>
<p>Gve this a grade [1-6]</p>
<form action="evaluation.php" method="post">
<select class="evalSelect">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
</select>
<input class="evalButton" type="submit" name="name" value="Give grade">
</form>
</section>
I'f I can use something like this, how can I get it to work togehter with the form above?
switch ($grade) {
case "1":
echo "Bad";
break;
case "2":
echo "Not so bad";
break;
case "3":
echo "Better";
break;
case "4":
echo "Even better";
break;
case "5":
echo "Good";
break;
case "6":
echo "Very good";
break;
}
?>
In order to do that, you need to add the value property to each option tag with a value. Then in PHP you can check wether evalSelect was set or not and what it contained.
Edit your form to:
<section class="evaluation">
<h2>Test</h2>
<p>More info here</p>
<p>Gve this a grade [1-6]</p>
<form action="evaluation.php" method="post">
<select class="evalSelect">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
<input class="evalButton" type="submit" name="name" value="Give grade">
</form>
</section>
And for the PHP this should work:
// evaluation.php
if (isset($_POST['evalSelect']))
{
$grade = $_POST['evalSelect'];
switch ($grade) {
case "1":
echo "Bad";
break;
case "2":
echo "Not so bad";
break;
case "3":
echo "Better";
break;
case "4":
echo "Even better";
break;
case "5":
echo "Good";
break;
case "6":
echo "Very good";
break;
}
}
Try something like this to echo your text:
<section class="evaluation">
<h2>Test</h2>
<p>More info here</p>
<p>Gve this a grade [1-6]</p>
<form action="evaluation.php" method="post">
<select class="evalSelect" name="evalSelect">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
</select>
<input class="evalButton" type="submit" name="name" value="Give grade">
</form>
</section>
And in evaluation.php
do something like:
$grade = $_POST['evalSelect'];
switch ($grade) {
case "1":
echo "Bad";
break;
case "2":
echo "Not so bad";
break;
case "3":
echo "Better";
break;
case "4":
echo "Even better";
break;
case "5":
echo "Good";
break;
case "6":
echo "Very good";
break;
}