TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack (1) Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 12-26-2007, 08:08 PM   1 links from elsewhere to this Post. Click to view. #1 (permalink)
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
 


LinkBacks (?)
LinkBack to this Thread: http://www.talkphp.com/absolute-beginners/1801-i-present-my-first-original-script.html
Posted By For Type Date
TalkPHP - Powered by vBulletin This thread Refback 12-26-2007 09:27 PM

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 06:50 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design