Jump to content

Archived

This topic is now archived and is closed to further replies.

qbit

Some questions about PHP

Recommended Posts

Basically I am creating a PHP quiz system to submit the quiz results to the myspace post bulliton page to all the quizzer to automatically share the quiz with all his/her friends. I have gotten it to work pretty well, now I am just making the code much cleaner. One of the biggest things is my submit.php page. Basically it takes the data from a quiz then formats a "textbox" and allows the user to press "submit" which then sends the whole thing to myspace. I have two questions about it.

First here is my code:

[code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

    <head>
        <meta http-equiv="content-type" content="text/html;charset=utf-8" />
        <meta name="generator" content="Adobe GoLive" />
        <title>Submitting to myspace.....</title>
        <link rel="stylesheet" type="text/css" media="screen" href="css.css" />
    </head>

    <body>
<?php
$question1 = $_POST['question1'];
$question2 = $_POST['question2'];
$question3 = $_POST['question3'];
$question4 = $_POST['question4'];
$question5 = $_POST['question5'];
$answer1 = $_POST['answer1'];
$answer2 = $_POST['answer2'];
$answer3 = $_POST['answer3'];
$answer4 = $_POST['answer4'];
$answer5 = $_POST['answer5'];
echo ('<div align="center"><form name="bulletinForm" method="post" target="_self" action="http://bulletin.myspace.com/index.cfm?fuseaction=bulletin.edit"><input type="hidden" value="0" name="groupID"><input class="htmlgenscom" type="hidden" maxLength="50" size="1" value="The Greatest Survey Ever" name="subject"><br><textarea class="htmlgenscom" name="body" type="hidden" rows="1" cols="20">');
echo ("<b>" . $question1 . "</b><br>" . $answer1 . "<br><br>");
echo ("<b>" . $question2 . "</b><br>" . $answer2 . "<br><br>");
echo ("<b>" . $question3 . "</b><br>" . $answer3 . "<br><br>");
echo ("<b>" . $question4 . "</b><br>" . $answer4 . "<br><br>");
echo ("<b>" . $question5 . "</b><br>" . $answer5 . "<br><br>");
echo ('</textarea><br><br><input type="submit" class="submit" value="Press here to Submit!" name="submit" target="_blank"></form></div>');
?>
    </body>

</html>
[/code]

My first question is how can I go about determining how many "questionX" and "answerX" are passed to my submit.php script. Basically, as it stands I have to manually write additional lines for every addition question that is in my quiz. This does not work well when you have multipul quizzes of different lengths... And since I would prefer not to have multipul submit scripts I would love for the script to automatically figure out how many questions and answers are passed to it and then writing the text area from there. I would think that a php loop would be the best, but I am new at php and am confused how to create a loop that could do this.

My second question is how can I make this page AUTOMATICALLY "submit" this whole script to myspace instead of making the user click the "submit" button a second time. Is this possible?

You can see my current script here: [a href=\"http://www.bloonlabs.com/myspacequiz/\" target=\"_blank\"]http://www.bloonlabs.com/myspacequiz/[/a] (only quiz 1 has any questions right now)

Share this post


Link to post
Share on other sites
First of all for the loop:

[code]
foreach ($_POST as $key => $value)
{
  if (preg_match ("/question_[0-9]+/", $key))
  {
    echo "this key is a question, number of the question is the second value of explode ("_", $key); and $value is the question content.
  }
}
[/code]

I don't understand what you mean by submitting twice please explain

Share this post


Link to post
Share on other sites
Ok, I got a version of that to work. Here is my code:

[code]
foreach ($_POST as $question => $answer)
      {
          $question = preg_replace('/_/', ' ', $question);
          $question = preg_replace('/submit/', '', $question);
          $answer = preg_replace('/Post this survey on your Myspace!/', '', $answer);
                       {
                          echo ("<b>" . $question . "</b><br>" . $answer . "<br><br>");
                    }
      }
[/code]

As for your question to what I ment by submitting twice, it will help if you can "see" the way the variables are passed:

[code]
Index.php -> (quizX) -> quiz.php -> (question => answer) -> submit.php
[/code]

Basically submit.php is where the question is. And as it stands, after the user fills in the entries on quiz.php they press submit, which directs them to submit.php where they have to press submit AGAIN. It is the only way I know of submitting the correctly formatted quiz. If there is a way for php to automatically submit a form or something of the like, it would save the user time. The latest version of my entire script can be found here: [a href=\"http://www.bloonlabs.com/myspacequiz/index.php\" target=\"_blank\"]http://www.bloonlabs.com/myspacequiz/index.php[/a]

Thanks!!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.