-1

Here is my code it is built to create an html form. It works but when you go to the next question it says $_SESSION doesn't exist? But I don't think I deleted it? What is wrong?

<?php

session_start();

$connect = mysql_connect("127.0.0.1","root","");
if (!$connect)
  {
  die("MySQL could not connect!");
  }

$DB = mysql_select_db('Contact');

if(!$DB)
{
die("My SQL could not select Database!");
}

if(empty($_SESSION['username']) || empty($_SESSION['password']))
{
    die("You have to <a href=\"login.php\"> login </a> before you visit this page!");
}
if(isset($_POST['submit']))
{
if(empty($_POST['type']) || empty($_POST['question']))
{
    if(empty($_SESSION['type']) || empty($_SESSION['question']))
    {
    die("<h3>You forgot something!</h3>");
    }
}
if(isset($_POST['type']) && isset($_POST['question']))
if($_POST['type'] == "radio" || $_POST['type'] == "checkbox")
{
    $_SESSION['question'] = $_POST['question'];
    $_SESSION['type'] = $_POST['type'];
    echo "<h3>Answer this to complete the current question...</h3>";
    echo "<h4>*** Go in order!</h4>";
    echo "Question: <b>" . $_POST['question'] . "</b></br>
          <form action=\"create.php\" method=\"POST\" />
          Option 1: <input type=\"text\" name=\"option1\" /></br>
          Option 2: <input type=\"text\" name=\"option2\" /></br>
          Option 3: <input type=\"text\" name=\"option3\" /></br>
          Option 4: <input type=\"text\" name=\"option4\" /></br>
          Option 5: <input type=\"text\" name=\"option5\" /></br>
          Option 6: <input type=\"text\" name=\"option6\" /></br>
          Option 7: <input type=\"text\" name=\"option7\" /></br>
          <input type=\"submit\" name=\"submit\" /></br>";
    echo "<hr>";
    die();
}
}

//If new option is clicked do this below....................

//Question 1-------------1-----------------1------------------------1---------------------1-------------------1
if($_SESSION['questions'] == 0)
{
    if(isset($_POST['submit']))
    {
    if(isset($_SESSION['type']) && isset($_SESSION['question']))
    {
    if($_SESSION['type'] == "checkbox" || $_SESSION['type'] == "radio")
    {
        if(empty($_POST['type']))
        {
        
        
        if(empty($_POST['option1']))
        {
            die("You forgot the first option! (Go in order)");
        }
        
        if($_POST['option7'] != "" && $_POST['option6'] != "" && $_POST['option5'] != "" && $_POST['option4'] != "" && $_POST['option3'] != "" && $_POST['option2'] != "" && $_POST['option1'] != "")
        {
            $_SESSION['q1'] = $_SESSION['question'] . "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option1\" />" . $_POST['option1'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option2\" />" . $_POST['option2'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option3\" />" . $_POST['option3'] .
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option4\" />" . $_POST['option4'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option5\" />" . $_POST['option5'] .
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option6\" />" . $_POST['option6'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option7\" />" . $_POST['option7'];
        }
        else
        {
            
        if($_POST['option6'] != "" && $_POST['option5'] != "" && $_POST['option4'] != "" && $_POST['option3'] != "" && $_POST['option2'] != "" && $_POST['option1'] != "")
        {
            $_SESSION['q1'] = $_SESSION['question'] . "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option1\" />" . $_POST['option1'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option2\" />" . $_POST['option2'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option3\" />" . $_POST['option3'] .
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option4\" />" . $_POST['option4'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option5\" />" . $_POST['option5'] .
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option6\" />" . $_POST['option6'];
        }
        else
        {
                
        if($_POST['option5'] != "" && $_POST['option4'] != "" && $_POST['option3'] != "" && $_POST['option2'] != "" && $_POST['option1'] != "")
        {
            $_SESSION['q1'] = $_SESSION['question'] . "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option1\" />" . $_POST['option1'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option2\" />" . $_POST['option2'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option3\" />" . $_POST['option3'] .
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option4\" />" . $_POST['option4'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option5\" />" . $_POST['option5'];
        }
        else
        {
                    
        if($_POST['option4'] != "" && $_POST['option3'] != "" && $_POST['option2'] != "" && $_POST['option1'] != "")
        {
            $_SESSION['q1'] = $_SESSION['question'] . "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option1\" />" . $_POST['option1'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option2\" />" . $_POST['option2'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option3\" />" . $_POST['option3'] .
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option4\" />" . $_POST['option4'];
        }
        else
        {
                              
        if($_POST['option3'] != "" && $_POST['option2'] != "" && $_POST['option1'] != "")
        {
            $_SESSION['q1'] = $_SESSION['question'] . "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option1\" />" . $_POST['option1'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option2\" />" . $_POST['option2'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option3\" />" . $_POST['option3'];
                              
        }
        else
        {
                            
        if($_POST['option2'] != "" && $_POST['option1'] != "")
        {
            $_SESSION['q1'] = $_SESSION['question'] . "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option1\" />" . $_POST['option1'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option2\" />" . $_POST['option2'];
        }
        else
        {
                    
        if($_POST['option1'] != "")
        {
            $_SESSION['q1'] = $_SESSION['question'] . "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q1\" value=\"option1\" />" . $_POST['option1'];
        }}}}}}}}
        $_SESSION['type'] = 0;
        $_SESSION['question'] = 0;
        }
    }
    }
    if(isset($_POST['type']) && isset($_POST['question']))
    {
    if($_POST['type'] == "textarea")
    {
        $_SESSION['q1'] = $_POST['question'] . "</br><textarea cols=\"20\" rows=\"4\" name=\"q1\"></textarea>";
    }
    if($_POST['type'] == "textbox")
    {
        $_SESSION['q1'] = $_POST['question'] . "<input type=\"text\" name=\"q1\" />";
    }
    }
    $_SESSION['questions']++;
    }
//Question 2-------------2-----------------2------------------------2---------------------2-------------------2
if($_SESSION['questions'] == 1)
{
    if(isset($_POST['submit']))
    {
    if(isset($_SESSION['type']) && isset($_SESSION['question']))
    {
    if($_SESSION['type'] == "checkbox" || $_SESSION['type'] == "radio")
    {
        if(empty($_POST['type']))
        {
        
        
        if(empty($_POST['option1']))
        {
            die("You forgot the first option! (Go in order)");
        }
        
        if($_POST['option7'] != "" && $_POST['option6'] != "" && $_POST['option5'] != "" && $_POST['option4'] != "" && $_POST['option3'] != "" && $_POST['option2'] != "" && $_POST['option1'] != "")
        {
            $_SESSION['q2'] = $_SESSION['question'] . "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option1\" />" . $_POST['option1'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option2\" />" . $_POST['option2'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option3\" />" . $_POST['option3'] .
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option4\" />" . $_POST['option4'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option5\" />" . $_POST['option5'] .
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option6\" />" . $_POST['option6'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option7\" />" . $_POST['option7'];
        }
        else
        {
            
        if($_POST['option6'] != "" && $_POST['option5'] != "" && $_POST['option4'] != "" && $_POST['option3'] != "" && $_POST['option2'] != "" && $_POST['option1'] != "")
        {
            $_SESSION['q2'] = $_SESSION['question'] . "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option1\" />" . $_POST['option1'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option2\" />" . $_POST['option2'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option3\" />" . $_POST['option3'] .
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option4\" />" . $_POST['option4'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option5\" />" . $_POST['option5'] .
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option6\" />" . $_POST['option6'];
        }
        else
        {
                
        if($_POST['option5'] != "" && $_POST['option4'] != "" && $_POST['option3'] != "" && $_POST['option2'] != "" && $_POST['option1'] != "")
        {
            $_SESSION['q2'] = $_SESSION['question'] . "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option1\" />" . $_POST['option1'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option2\" />" . $_POST['option2'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option3\" />" . $_POST['option3'] .
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option4\" />" . $_POST['option4'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option5\" />" . $_POST['option5'];
        }
        else
        {
                    
        if($_POST['option4'] != "" && $_POST['option3'] != "" && $_POST['option2'] != "" && $_POST['option1'] != "")
        {
            $_SESSION['q2'] = $_SESSION['question'] . "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option1\" />" . $_POST['option1'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option2\" />" . $_POST['option2'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option3\" />" . $_POST['option3'] .
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option4\" />" . $_POST['option4'];
        }
        else
        {
                              
        if($_POST['option3'] != "" && $_POST['option2'] != "" && $_POST['option1'] != "")
        {
            $_SESSION['q2'] = $_SESSION['question'] . "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option1\" />" . $_POST['option1'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option2\" />" . $_POST['option2'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option3\" />" . $_POST['option3'];
                              
        }
        else
        {
                            
        if($_POST['option2'] != "" && $_POST['option1'] != "")
        {
            $_SESSION['q2'] = $_SESSION['question'] . "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option1\" />" . $_POST['option1'] . 
                              "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option2\" />" . $_POST['option2'];
        }
        else
        {
                    
        if($_POST['option1'] != "")
        {
            $_SESSION['q2'] = $_SESSION['question'] . "</br><input type=\"" . $_SESSION['type'] . "\" name=\"q2\" value=\"option1\" />" . $_POST['option1'];
        }}}}}}}}
        $_SESSION['type'] = 0;
        $_SESSION['question'] = 0;
        }
    }
    }
    if(isset($_POST['type']) && isset($_POST['question']))
    {
    if($_POST['type'] == "textarea")
    {
        $_SESSION['q2'] = $_POST['question'] . "</br><textarea cols=\"20\" rows=\"4\" name=\"q2\"></textarea>";
    }
    if($_POST['type'] == "textbox")
    {
        $_SESSION['q2'] = $_POST['question'] . "<input type=\"text\" name=\"q2\" />";
    }
    }
    }
echo "<h3>Your Form.....</h3>";        
echo "<html><body>" . $Car . "</br>";
echo $Num . "</br>";
if(isset($_SESSION['q1']))
{
echo $_SESSION['q1'] . "</br>";
}
if(isset($_SESSION['q2']))
{
echo $_SESSION['q2'] . "</br>";
}
if(isset($_SESSION['q3']))
{
echo $_SESSION['q3'] . "</br>";
}
if(isset($_SESSION['q4']))
{
echo $_SESSION['q4'] . "</br>";
}
if(isset($_SESSION['q5']))
{
echo $_SESSION['q5'] . "</br>";
}
if(isset($_SESSION['q6']))
{
echo $_SESSION['q6'] . "</br>";
}
echo "</body></html>";
echo "<a href=\"undo.php\">Undo your last question</a>";
    

?>
<html>
<body>
<hr>
<form action="create.php" method="POST" />
<h3>Add New Option:</h3>
<input type="radio" name="type" value="textbox">Textbox</option>
<input type="radio" name="type" value="textarea">Text Area</option>
<input type="radio" name="type" value="checkbox">Checkbox</option>
<input type="radio" name="type" value="radio">Radiobox</option>
</br>Question: <input type="text" name="question" /></br>
<input type="submit" name="submit" />
</form>

</body>
</html>
3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by MooGeek
0

hi joe34
if u can plz attach the src file to get better view of this code since
it is very long ... and also why u dont use functions to generate ur html
code depends on selection and option rather than u do it manually all the time
via if statements?
waiting for ur response

0

or atleast:

-Upload the PHP files and the SQL Exported file. (.sql)
-Put a Comment on every Page on what's the problem

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.