Include form result in SELECT statement

Hi,

I have a php formscript that compares form input to certain tables and gives me a result.

The script looks like this:

====================================================================================

<?php
$host = "localhost";
$user = "root";
$pass = "";
$dbname = "test";
$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);
$sql = "SELECT A.FormId,
      B.SubmissionId,
      B.DateSubmitted,
	  ( SELECT FieldValue 
              FROM jos_RSFORM_SUBMISSION_VALUES 
              WHERE FieldName = 'name'
              AND SubmissionId = B.SubmissionId ) as Name, 
         ( SELECT FieldValue 
              FROM jos_RSFORM_SUBMISSION_VALUES 
              WHERE FieldName = 'email'
              AND SubmissionId = B.SubmissionId ) as Email 
      FROM jos_RSFORM_FORMS A

INNER
    JOIN jos_RSFORM_SUBMISSIONS B
        ON B.FormId = A.FormId

INNER
    JOIN jos_RSFORM_SUBMISSION_VALUES C
        ON C.SubmissionId = B.SubmissionId 
          AND C.FieldName = 'Regio'
          AND C.FieldValue = '" .mysql_real_escape_string ($_POST['form']['Volunteer']) . "'
INNER
    JOIN jos_RSFORM_SUBMISSION_VALUES D
        ON D.SubmissionId = B.SubmissionId 
          AND D.FieldName = 'capaciteit'
          AND D.FieldValue LIKE '%" . mysql_real_escape_string ($_POST['form']['Capacity']) . "%'

 WHERE A.FormId = 2";

$query = mysql_query($sql); 

echo "<table border='1' bgcolor='#CCCCCC' style='border-collapse:collapse'>";
echo "<tr> <th>[ Name ]</th> <th>[ Email ]</th> <th>[ Submitted ]</th> <th>[ SubID ]</th></tr>";
while ($row = mysql_fetch_array($query)) 
{
echo "<tr><td>"; 
echo $row['DateSubmitted'];
echo "</td><td>";
echo $row['SubmissionId'];
echo "</td><td>";
echo $row['Name'];
echo "</td><td>";
echo $row['Email'];
echo "</td></tr>";
} 

?>

==============================================================================

The script workes great.
I would like to add the input, given in the form, be visible in the query output.
Now there is an comparison done with the forminput at the “INNER JOIN” parts of the script but the actual input is not shown in the query results.
I tried already things like:

     ( SELECT * 
       FROM jos_RSFORM_SUBMISSION_VALUES 
      WHERE FieldName = '" .mysql_real_escape_string ($_POST['form']['Volunteer']) . "') as Volunteer

but that gives me syntax errors.

Are the things i want possible, and how should i fix it ?

Thanks in advance,
Mesjoggah

You shouldn’t get PHP syntax errors from what you have. Are they PHP or SQL errors?

Can you echo the query?
Have you done var_dump($_POST) to see that it has the data you expect?