Thank You for Participating!


Additional information about what this script does:

Storing data to a database with PHP

This PHP script receives the user responses from the form, and stores the data in the table "expdata1" in the "orval" database. In actual practice, the only XHTML content in this page would be a thank you message to the user or directions for the next part of the experiment. For purposes of example, a bit more explanation of what is going on is included.

PHP automatically creates variables corresponding to the form's input elements' "id" or "name" attributes when the form data is "post"ed to this script. The "value" of the input field "answer_1" for example is stored in the variable "$answer_1" in this script.

Here are the PHP commands used to create a new record in the table expdata1 for this participant's data. (See the source code on the server for additional information in the comments in the code.)

  <?php
     $db = mysql_connect("localhost", "orval");
     mysql_select_db("orval",$db);
     $sql = sprintf('INSERT INTO expdata1 (name, id, condition, answer1, answer2) VALUES ("", "", "%s", "%s", "%s")',
        $condition, $question_1, $question_2);
     $resultInput = mysql_query ($sql, $db);
  ?> 

This is the SQL command that was sent to the database:

Notice that the first field (subNum) was omitted. This is because that field uses the mysql "auto-increment" feature to automatically add one to the previous subNum whenever a new entry is created. There are also two empty fields (name and id) that are not used but could be added to the input form if needed (for confidential participant codes for Intro Psych participants, for example).

Here are the contents of the table expdata1. Verify that the data you entered was recorded. You may also want to look at the source code to see how the table was created.

\n"); for($Field=0; $Field < mysql_num_fields ($Result); $Field++) { print("\n"); } print("\n"); //loop through rows for($Row=0; $Row < mysql_num_rows($Result); $Row++) { print("\n"); // print out each field for($Field=0; $Field < mysql_num_fields($Result); $Field++) { print("\n"); } print("\n"); } print("
"); print(""); print(mysql_field_name($Result, $Field) . " "); print(""); print("
"); print(mysql_result($Result, $Row, $Field)); print("
\n"); ?>