The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.34 / 5.00 31,296 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.07 / 5.00 10,082 ViewsI know HTML and CSS, I just started PHP today. I'm trying to make a quiz for my school, and I'm getting this error. I'm lost. Can someone tell me where I went wrong?
Index.html page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="results.php" method="post">
Question 1: Do you like working with your hands?<br />
<input type="radio" name="q1" value="yes" />Yes<br />
<input type="radio" name="q1" value="no" />No<br />
Question 2: Do you like technology?<br />
<input type="radio" name="q2" value="yes" />Yes<br />
<input type="radio" name="q2" value="no" />No<br />
Question 3: Do you like wood?<br />
<input type="radio" name="q3" value="yes" />Yes<br />
<input type="radio" name="q3" value="no" />No<br />
Question 4: Do you like stone?<br />
<input type="radio" name="q4" value="yes" />Yes<br />
<input type="radio" name="q4" value="no" />No<br />
Question 5: Do you like outside?<br />
<input type="radio" name="q5" value="yes" />Yes<br />
<input type="radio" name="q5" value="no" />No<br />
Question 6: Do you like hammering nails?<br />
<input type="radio" name="q6" value="yes" />Yes<br />
<input type="radio" name="q6" value="no" />No<br />
<input type="submit" value="Determine your shop" />
</form>
</body>
</html>
Results.php Page
<html>
<head>
<title>Your results</title>
<?php
$score = 0;
if ($_POST['q1'] == 'yes')
$score = $score + 1;
if ($_POST['q2'] == 'yes')
$score = $score + 1;
if ($_POST['q3'] == 'yes')
$score = $score + 1;
if ($_POST['q4'] == 'yes')
$score = $score + 1;
if ($_POST['q5'] == 'yes')
$score = $score + 1;
if ($_POST['q6'] == 'yes')
$score = $score + 1;
?>
</head>
<body>
<h1>Here is your results</h1>
<?php
echo 'Your coolness score was ' . $score . '/5<br><br>';
if ($score <= 2)
echo 'You are not very cool!';
else if ($score == 3)
echo 'Congratulations, a perfect score!';
else
echo 'Not bad, you scored average';
?>
</body>
</html>
Fighting for peace is like screwing for virginity.
- George Carlin
Also, It's not really an error.
Instead of echoing what it's supposed to, it echos a bunch of code.
I got this php code off this site, it works fine on the site, but it doesn't work for me.
Fighting for peace is like screwing for virginity.
- George Carlin
Damn, the code got all screwed up because of Newgrounds use of html for post styling.
Fighting for peace is like screwing for virginity.
- George Carlin
index.html should be index.php.
html extension does not support PHP unless you treat it as PHP in a .htaccess.
Still didn't work.
I'll give the code in the code tag this time.
Index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="results.php" method="post">
<b>Question 1: Do you like working with your hands?</b><br />
<input type="radio" name="q1" value="yes" />Yes<br />
<input type="radio" name="q1" value="no" />No<br />
<b>Question 2: Do you like technology?</b><br />
<input type="radio" name="q2" value="yes" />Yes<br />
<input type="radio" name="q2" value="no" />No<br />
<b>Question 3: Do you like wood?</b><br />
<input type="radio" name="q3" value="yes" />Yes<br />
<input type="radio" name="q3" value="no" />No<br />
<b>Question 4: Do you like stone?</b><br />
<input type="radio" name="q4" value="yes" />Yes<br />
<input type="radio" name="q4" value="no" />No<br />
<b>Question 5: Do you like outside?</b><br />
<input type="radio" name="q5" value="yes" />Yes<br />
<input type="radio" name="q5" value="no" />No<br />
<b>Question 6: Do you like hammering nails?</b><br />
<input type="radio" name="q6" value="yes" />Yes<br />
<input type="radio" name="q6" value="no" />No<br />
<input type="submit" value="Determine your shop" />
</form>
</body>
</html>
Results.php
<html>
<head>
<title>Your results</title>
<?php
$score = 0;
if ($_POST['q1'] == 'yes')
$score = $score + 1;
if ($_POST['q2'] == 'yes')
$score = $score + 1;
if ($_POST['q3'] == 'yes')
$score = $score + 1;
if ($_POST['q4'] == 'yes')
$score = $score + 1;
if ($_POST['q5'] == 'yes')
$score = $score + 1;
if ($_POST['q6'] == 'yes')
$score = $score + 1;
?>
</head>
<body>
<h1>Here is your results</h1>
<?php
echo '<b>Your coolness score was ' . $score . '/5</b><br><br>';
if ($score <= 2)
echo 'You are not very cool!';
else if ($score == 3)
echo 'Congratulations, a perfect score!';
else
echo 'Not bad, you scored average';
?>
</body>
</html> Fighting for peace is like screwing for virginity.
- George Carlin
You are running this off of a web/virtual server with php like (xampp) correct?
What exactly is the error? I didn't see you posting any error, just correct code. What is happening and what do you expect to happen?
At 11/18/09 01:11 AM, fourthfrench wrote: You are running this off of a web/virtual server with php like (xampp) correct?
No, I'm testing this all locally. I have PHP installed.
At 11/18/09 03:53 AM, hesselbom wrote: What exactly is the error? I didn't see you posting any error, just correct code. What is happening and what do you expect to happen?
Here's what happens: I fill out the quiz, I the button to continue to the page that should show-
Here is your results
Your coolness score was you are not very cool!
Something along those lines.
But instead it shows:
Here is your results
Your coolness score was ' . $score . '/5
'; if ($score <= 2) echo 'You are not very cool!'; else if ($score == 3) echo 'Congratulations, a perfect score!'; else echo 'Not bad, you scored average'; ?>
I'm not sure where I went wrong, I'm not totally familiar with PHP.
Fighting for peace is like screwing for virginity.
- George Carlin
Try changing it to this:
<h1>Here is your results</h1>
<?php
echo '<b>Your coolness score was ';
if ($score <= 2){
echo 'You are not very cool!';
}else if ($score == 3){
echo 'Congratulations, a perfect score!';
}else{
echo 'Not bad, you scored average';
}
echo '</b><br><br>';
?> At 11/18/09 08:09 PM, Jon-86 wrote: Try changing it to this:
Bugger theirs a bug in that. Well its late and I need to sleep. But you should get the right idea from what I posted. Although your code is bloated but that dost matter since your only starting!
At 11/18/09 08:09 PM, Jon-86 wrote: Try changing it to this:
Still doesn't work. It comes out to:
Here is your results
Your coolness score was '; if ($score <= 2){ echo 'You are not very cool!'; }else if ($score == 3){ echo 'Congratulations, a perfect score!'; }else{ echo 'Not bad, you scored average'; } echo '
'; ?>
I tried putting else in it:
if ($_POST['q1'] == 'yes')
$score = $score + 1
else
$score = $score + 0;
But that didn't work either.
Fighting for peace is like screwing for virginity.
- George Carlin
Move all of this crap to the body and see if it displays it as well.
<?php
$score = 0;
if ($_POST['q1'] == 'yes')
$score = $score + 1;
if ($_POST['q2'] == 'yes')
$score = $score + 1;
if ($_POST['q3'] == 'yes')
$score = $score + 1;
if ($_POST['q4'] == 'yes')
$score = $score + 1;
if ($_POST['q5'] == 'yes')
$score = $score + 1;
if ($_POST['q6'] == 'yes')
$score = $score + 1;
?>
I suspect it will. I don't think you have php set up properly. Your script works fine for me. Someone else asked if you had xampp, you didn't say yes or no, just that you had php installed. You should probably download it if you don't have it. If you do have it, you need to actually start the server and put the php file in the htdocs folder.
At 11/18/09 10:06 PM, gapern wrote: http://www.apachefriends.org/en/xampp.ht ml
Moving it didn't work.
I'm downloading xampp now. Someone told me you could just install php and it would work fine, I didn't think you needed anything else.
Fighting for peace is like screwing for virginity.
- George Carlin
also with your if statements, u should close them
if () {
//code
}