As I explained in my introduction, I'm new to learning PHP, but I do know html fairly well (although far from an expert) and I understand PHP implementation (what it's for, what it can do, when it should be used etc.)
So I have a very basic question for you all. I'm putting together a test site just to learn basic PHP hands-on. The site is amiarepublicanordemocrat dot com. I have the form setup in index.php and I have results.php created. But I can't figure out how to echo what the user's answers were, while associating an extra snippet of text next to each answer.
There are only two options per question and all I want results.php to display is the user's answer to each question.
Here is the form from index.php
<form name="question1" action="results.php" method="post"> <h4>1. Are you pro-life (against abortion) or pro-choice (for abortion)?</h4> <input type="radio" name="q1" value="q1a1"/> : I am pro-life<br /> <input type="radio" name="q1" value="q1a2"/> : I am pro-choice <h4><strong>2.</strong> Do you believe that gun rights are necessary to preserve safety, freedom and to protect us from tyranny, or do you believe unarmed citizens are safer citizens?</h4> <input type="radio" name="q2" value="q2a1"/> : I support gun rights<br /> <input type="radio" name="q2" value="q2a2"/> : I believe citizens should be unarmed <h4><strong>3.</strong> Do you believe in free markets (limited regulation on business) or do you believe the government should regulate business' to any extent necessary?</h4> <input type="radio" name="q3" value="q3a1"/> : I support free markets<br /> <input type="radio" name="q3" value="q3a2"/> : I support regulating to any extent necessary<br /> <br /> <input type="submit" value="Tell me if I'm a Republican or Democrat!" /> </form>
And here is the PHP from results.php
<?php
$qone = $_POST['q1a1'];
$qone = $_POST['q1a2'];
$qtwo = $_POST['q2a1'];
$qtwo = $_POST['q2a2'];
$qthree = $_POST['q3a1'];
$qthree = $_POST['q3a2'];
if ($qone == "q1a1"){
echo "Your answer to question 1 is: I am pro-life. This is a republican/conservative view.<br />";
}elseif ($qone == "q1a2"){
echo "Your answer to question 1 is: I am pro-choice. This is a democrat/liberal view.<br />";
}elseif($qtwo == "q2a1"){
echo "Your answer to question 2 is: I support gun rights. This is a republican/conservative view.<br />";
}elseif ($qtwo == "q2a2"){
echo "Your answer to question 2 is: I believe citizens should be unarmed. This is a democrat/liberal view.<br />";
}elseif ($qthree == "q3a1"){
echo "Your answer to question 3 is: I support free markets. This is a republican/conservative view.<br />";
}elseif ($qthree == "q3a2"){
echo "Your answer to question 3 is: I support regulating to any extent necessary. This is a democrat/liberal view.<br />";
}
else {
echo "Well crap. If you're seeing this then I screwed up the code and it's not finding the answer variables. I'm thinking I need to learn more about arrays... need to figure out how to make results.php understand the difference between the two answers for each question. I think this is done by setting values for each answer in index.php then using arrays to 'convert' them over so they can be translated into the results.php page..?..";
}
?>
Am I WAY off or is just a simple little thing that I'm doing wrong? Thanks!!
Edited by joshspaulding, 08 December 2012 - 10:55 AM.












