I'm very new to PHP - as in, I just started trying to figure it out a few days ago. I'm working on a MA thesis for which I'm collecting data over the internet. I found a seemingly simple PHP script that I could use with a <form method="post"> tag to email the results to myself.
This is the PHP script I'm using (except I only left in the names of the first few variables to save space):
// Get all $_POST variables
foreach($_POST as $var => $val)
{
${$var} = $val;
}
// Set up the email body
$body_body = $adfid.",".$relig12.",".$attend12.",".$relig1st.",".$seeker.",".$religity.",".$belief.",".$expsprt.",".$expone.",".$expoob.",".$expecst.",".$attend;
The questions in the form are simple enough:
<tr>
<td>1. How personally religious were you at age 12?</td>
<td>
<input type="radio" name="relig12" value="0"/>Not religious at all</br>
<input type="radio" name="relig12" value="1"/>Not very religious</br>
<input type="radio" name="relig12" value="2"/>Somewhat religious</br>
<input type="radio" name="relig12" value="3"/>Very religious</td>
</tr>
When I fill out the form and press Submit, I receive an error message for every variable, like this:
Notice: Undefined variable: adfid in /pass/home/10/e/eas295/www/process.php on line 7
Notice: Undefined variable: relig12 in /pass/home/10/e/eas295/www/process.php on line 7
Notice: Undefined variable: attend12 in /pass/home/10/e/eas295/www/process.php on line 7
My intention is to have the email simply contain the value of each inputted variable separated by commas in a single line so that each email will be a line in a CSV file that I can then transfer into a statistical software package. I think that $body_body part is correct, but for some reason the $_POST variables don't seem to be transferring into local variables, because the email I receive contains nothing but commas (all the variable values missing).
I have a feeling this is very simple but I really haven't a clue what I'm doing. I understand the foreach loop is supposed to prevent me from having to write a $var = $_POST['var'] for each of the 120+ variables in my form, but I don't understand why it's not working for me. After some google searching I also attempted to use
extract($_POST);
rather than the foreach loop, but got the same error/email without any variable values.
Any suggestions?