View Single Post
Old 12-26-2007, 08:08 PM   #1 (permalink)
obolus
The Acquainted
 
obolus's Avatar
 
Join Date: Oct 2007
Location: florida
Posts: 110
Thanks: 36
obolus is on a distinguished road
Default I present... my first original script

Hey all, this is my first ever 100% original script. No snippets copied from outside sources or nothin'. It's a pretty simple quizzer script that I've been messing with just to have a project to experiment with and whatnot. I'm sure it's pretty elementary to some of you. =P

I'm looking for any feedback/tips. All are appreciated!

Originally it was just the ifelse statements in the pquiz.php file, then I decided to put what I've read about OOP to test and advance the script a little bit more.

See it in action here: Quiz Link

And of course, the source...

index.php
HTML Code:
<html>
<head>
<title>PHP Quizzer</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<form method="post" action="pquiz.php">

<p>Same questions, same answers. I'll make a more challenging quiz later on. =)</p>
<br />
What is the best language? <input name="questionone" type="text" />
<br />
<br />
What is the best language? <input name="questiontwo" type="text" />
<br />
<br />
What is the best language? <input name="questionthree" type="text" />
<br />
<br />
What is the best language? <input name="questionfour" type="text" />
<br />
<br />
What is the best language? <input name="questionfive" type="text" />
<br />
<input type="submit" value="Send!" />

</form>

</body>
</html>
pquiz.php
PHP Code:
<?php

// Get me mah classes!
include 'class.php';

// Call up the Class, give vars user input (answers), then run them through the appropriate functions of the class.

$zaQuizone = new zlQuiz();
$zaQuiztwo = new zlQuiz();
$zaQuizthree = new zlQuiz();
$zaQuizfour = new zlQuiz();
$zaQuizfive = new zlQuiz();

$zaQuizone->qone $_POST['questionone'];
$zaQuiztwo->qtwo $_POST['questiontwo'];
$zaQuizthree->qthree $_POST['questionthree'];
$zaQuizfour->qfour $_POST['questionfour'];
$zaQuizfive->qfive $_POST['questionfive'];

$zaQuizone->questionone();
$zaQuiztwo->questiontwo();
$zaQuizthree->questionthree();
$zaQuizfour->questionfour();
$zaQuizfive->questionfive();

?>
class.php
PHP Code:
class zlQuiz {

    
// pub vars
    
public $qone;
    public 
$qtwo;
    public 
$qthree;
    public 
$qfour;
    public 
$qfive;

// Question one
function questionone() {
    echo 
"<b>Question #1:</b> What is the best language?<br /><br /><i>Your answer: ".$this->qone." <br /><br />";

        if (
$this->qone == 'PHP') {
            echo 
'<font color="#009900">CORRECT</font><br /><hr /><br />';
        } else {
            echo 
'<font color="#CC0000">INCORRECT</font><br />Correct Answer: PHP<br /><hr /><br />';
        }

}

// Question two
function questiontwo() {
    echo 
"<b>Question #2:</b> What is the best language?<br /><br /><i>Your answer: ".$this->qtwo." <br /><br />";

        if (
$this->qtwo == 'PHP') {
            echo 
'<font color="#009900">CORRECT</font><br /><hr /><br />';
        } else {
            echo 
'<font color="#CC0000">INCORRECT</font><br />Correct Answer: PHP<br /><hr /><br />';
        }

}

// Question three
function questionthree() {
    echo 
"<b>Question #3:</b> What is the best language?<br /><br /><i>Your answer: ".$this->qthree." <br /><br />";

        if (
$this->qthree == 'PHP') {
            echo 
'<font color="#009900">CORRECT</font><br /><hr /><br />';
        } else {
            echo 
'<font color="#CC0000">INCORRECT</font><br />Correct Answer: PHP<br /><hr /><br />';
        }

}

// Question four
function questionfour() {
    echo 
"<b>Question #4:</b> What is the best language?<br /><br /><i>Your answer: ".$this->qfour." <br /><br />";

        if (
$this->qfour == 'PHP') {
            echo 
'<font color="#009900">CORRECT</font><br /><hr /><br />';
        } else {
            echo 
'<font color="#CC0000">INCORRECT</font><br />Correct Answer: PHP<br /><hr /><br />';
        }
        
}

// Question five
function questionfive() {
    echo 
"<b>Question #5:</b> What is the best language?<br /><br /><i>Your answer: ".$this->qfive." <br /><br />";

        if (
$this->qfive == 'PHP') {
            echo 
'<font color="#009900">CORRECT</font><br /><hr /><br />';
        } else {
            echo 
'<font color="#CC0000">INCORRECT</font><br />Correct Answer: PHP<br /><hr /><br />';
        }

}


// End of class


?> 
obolus is offline  
Reply With Quote