This week we will look at an example of using PHP to conduct a simple experiment on the web. The "experiment" consists of 2 questions, presented in one of two versions.
The first PHP script, experiment1.php, accesses the expdata1 table in the orval Mysql database on the course server to determine the condition (1 or 2) for the current participant. It then accesses the experiment1_stimuli table to get the stimuli to present. It presents the stimuli in an XHTML form. The "action" for the form sends the responses to a second PHP script.
The second PHP script experiment1-storeData.php then stores the data to the expdata1 table in the database, and displays its contents in an XHTML table.
First run the experiment a couple of times and observe the results as recorded in the table. Be sure to reload the page before submitting data a second time.
1. Copy the two PHP files used to run the experient to your public_html directory (or a subdirectory if you wish). Create a table in your database on the course server to store the data in. Also create a second table and place your experimental stimuli in it. Then edit the PHP files to run your experiment and save the data in your database. Place a link to your experiment on your home page on the course server.
REMINDER: PHP scripts are executed by the server and the results inserted into the web page before the XHTML is sent to the browser. As a result, you can not use "view source" in your browser to see the PHP code. You must telnet into the server and look at the ".php" files directly, rather than through a browser.