PHP & Hosted Applications
by Ahmad Abualsamid

Listing One
<form method="post" name="create_survey" action="step2.php" 
onsubmit="return validate();">
    <table border=0 cellspacing=2 cellpadding=2>
        <tr>
            <th> Please enter the survey's name </th>
            <td> <input type="text" name="survey_name"> </td>
        </tr>
        <tr>
            <th> Please enter a short description </th>
            <td> <input type="text" name="survey_description"> </td>
        </tr>
        <tr>
            <th> Please enter the number of questions in the survey </th>
            <td> <input type="text" name="survey_questions"> </td>
        </tr>
        <tr> 
            <td> <input type="Submit" Value="Create Survey">
        </tr>
</table>    
</form>

Listing Two
<html>
<head>
</head>
<body>
<form id="create_questions" name="create_questions" 
                                          action="step3.php" method=post>
<?
    printf ("<input type='hidden' name=survey_questions 
                                          value=$survey_questions>");
    for ($i=0;$i<$survey_questions;$i++) {
        $j = $i+1;
        printf ("Select Question Type for Question $j <p>");
        printf ("<select name='questions_type[$i]'>");
        printf ("<option value=0> Free Text Answer");
        printf ("<option value=1 selected> Radio Button Answer");
        printf ("<option value=2> Check Box Answer");
        printf ("</select>");
        printf ("<br>If Radio Button or Check Box:<br> <dl> ");
        printf ("<dd> Number of Choices ");
        printf ("<input type=text length=5 name=choices[$i] value=3><br>");
        printf ("<dd><input type=checkbox name=isCheck[$i] value=selected>");
        printf ("Provide an Other option</dl>");
        printf ("<hr color=blue>");
    }
?>
<input type="submit" value="Goto Step 3">
</form>
</body>
</html>


Listing Three
<html>
<body>
    <form method=post name=create id=create action="createit.php">
    <?
        printf ("<input type='hidden' name=survey_questions 
                                               value=$survey_questions>");
        $choice_counter=0;
        for ($i=0;$i<$survey_questions;$i++) {
            echo "<br>";
            $j=$i+1;
            echo "<big>Question #$j is: </big> ";
            echo "<input type=text id=question_text[$i] 
                                               name=question_text[$i]>\n";
            echo "<input type='hidden' name=choices[$i] 
                                               value=$choices[$i]>\n";
            printf ("<input type=hidden id=questions_type[$i] 
                      name=questions_type[$i] value=$questions_type[$i]>\n");
            switch ($questions_type[$i]) {
                case 0:
                    echo "<p>";
                    break;
                case 1:
                    printf("<br>  ");
                    for ($counter=0;$counter<$choices[$i];$counter++) {
                        printf ("Choice #$counter: <input type=text 
                            id=choice_text[$choice_counter] 
                            name=choice_text[$choice_counter]>\n");
                        if ($counter && ($counter % 2 == 0)) echo "<br>\n";
                        $choice_counter++;
                    }
                    break;
                case 2:
                    printf("<br>  ");
                    for ($counter=0;$counter<$choices[$i];$counter++) {
                        printf ("Choice #$counter: <input type=text 
                            id=choice_text[$choice_counter] 
                            name=choice_text[$choice_counter]>\n");
                        if ($counter && ($counter % 2 == 0)) echo "<br>\n";
                        $choice_counter++;
                    }
                    break;
                default:
                    echo $questions_type[$i];
                    break;
            }
            echo "<hr color=red>";
        }
    ?>
    <input type="submit" Value="Create Survery" >
    </form>
</body>
</html>

Listing Four
$stmt = "insert into surveys.survey (name,lastupdate,DateCreated,OwnerID, ";
    $stmt = $stmt . "Description,isClosed) values 
                                            ('$survey_name',now(),now(),0";
    $stmt = $stmt . ",'$survey_description',0)";
    if (!(mysql_query($stmt)) {
{
        printf ("Failed in Creating the Survey Entry...");
        exit();
    }


Listing Five
<%
            Dim myObject
            Set myObject = Server.CreateObject("MyProject.MyClass")
            Dim myString
            myString = myObject.GetDataBaseName
            Response.Write "The Database name is " & myString
        %>


Listing Six
        <?
            $myObject = new COM("MyProject.MyClass");
            $myString = $myObject->GetDataBaseName();
            echo "The Database name is $myString";
        ?>

Example 1: 
Create table survey (ID not int not null auto_increment, name varchar(255), LastUpdate date, DateCreated Date, OwnerID number, Description varchar(255), IsClosed smallint, primary key(ID));

Example 2: 
Create Table Questions (ID int not null auto_increment, SurveyID int not null, QuestionType smallint, QuestionText varchar(255), NumberOfChoices smallint, isRequired smallint, primary key (ID), index (SurveyID));

Example 3: 
Create Table Choices (ID int not null auto_increment, QuestionID int not null, Text varchar(255), primary key (ID), index (QuestionID));

Example 4: 
Create Table Answers (SurveyID number, QuestionID number, ChoiceSelected smallint, AnswerText varchar(255));






1

