Not Submitting Form in PHP

Viewed 34

So I'm tinkering with PHP, never really messed with it so forgive me if this is a very noob question. I've retrieved an old small website from a friend from a game server a few years ago. I'm playing around with it and noticed right off that the form to register an account is not submitting. I was hoping to get some help with what is going on here as I'm not sure I understand. I've never see if(isset($_POST before and I'm sort of familiar with else but this I cannot wrap my brain around. I'd also like to add that Question 1 through 5 are radio selections

$totalCorrect = 0;
    if(isset($_POST['question-1-answers'])) 
    {
        $answer1 = $_POST['question-1-answers'];
        $totalCorrect ++;
    }
     else
     {
        $answer1 = "";
     }

    if(isset($_POST['question-2-answers'])) 
    {
        $answer2 = $_POST['question-2-answers'];
        $totalCorrect ++;
    }
     else
    {
        $answer2 = "";
    }

    if(isset($_POST['question-3-answers'])) 
    {
        $answer3 = $_POST['question-3-answers'];
        $totalCorrect ++;
    }
    else
    {
        $answer3 = "";
    }

    if(isset($_POST['question-4-answers'])) 
    {
        $answer4 = $_POST['question-4-answers'];
        $totalCorrect ++;
    }
    else
    {
        $answer4 = "";
    }

    if(isset($_POST['question-5-answers'])) 
    {
        $answer5 = $_POST['question-5-answers'];
        $totalCorrect ++;
    }
    else
    {
        $answer5 = "";
    }

    if (strlen($_POST['story']) == 0)
    {
        $story = "";
    }
    else
    {
        $story = $_POST['story'];
        $totalCorrect ++;
    }
    if (strlen($_POST['policy']) == 0)
    {
        $policy = "";
    }
    else
    {
        $policy = $_POST['policy'];
        $totalCorrect ++;
    }
    if (strlen($_POST['terms']) == 0)
    {
        $terms = "";
    }
    else
    {
        $terms = $_POST['terms'];
        $totalCorrect ++;
    }
    if (strlen($_POST['situation']) == 0)
    {
        $situation = "";
    }
    else
    {
        $situation = $_POST['situation'];
        $totalCorrect ++;
    }

    if($totalCorrect == 9)
    {
        $_SESSION['question-1-answers'] = $answer1;
        $_SESSION['question-2-answers'] = $answer2;
        $_SESSION['question-3-answers'] = $answer3;
        $_SESSION['question-4-answers'] = $answer4;
        $_SESSION['question-5-answers'] = $answer5;
        $_SESSION['story'] = $story;
        $_SESSION['terms'] = $terms;
        $_SESSION['situation'] = $situation;
        $_SESSION['policy'] = $policy;
        $registerstep = 2;
    }
    else {
        array_push($errors, "<p style='color:red; text-align:center;'>You did not answer all of the questions!</p>");

    }
}
1 Answers

You have piece of code without the HTTP post script . That script is checking the results from a post and session information ...

Session information

// Initialize the session
session_start();

to save somthing to the session you save it as an array

// Set session variables
$_SESSION["favcolor"] = "green";
$_SESSION["favanimal"] = "cat";

to retrieve all session variables

//use print_r
print_r($_SESSION); 

//or individual values
$_SESSION["favanimal"]
$_SESSION["favcolor"]

Make sure you enclose the above in PHP tags to work

Post Values

There few ways to post things to a php script

  1. XHR(Ajax)
  2. PHP HTML forms
  3. PHP Curl posts

the following is an example of posting values to a php script using CURL

<?php
$url = 'http://www.someurl.com';
$myvars = 'myvar1=' . $myvar1 . '&myvar2=' . $myvar2;

$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec( $ch );
?>

Creating one file to create the session and post script you should be able to set some values of your script . Like I say what you have provided there is the second phase to the post .ie the validation but not the post transaction .

Remeber with regards to Sessions the session_start(); must be used in both files in order to use session variables .

Related