Please could some php expert look at this code and let me know where I have gone wrong? Been at it for 2 days but can't achieve what I want!
The form part is ok and displays all items in database for a certain user. Even the form send function works and the returning thankyou page.
THE PROBLEM IS...
On clicking the 'form send button' a seperate email is sent to the user and me (as I get a copy) for every item the user has in the database.
Also a thank you is displayed for every item after sending.
Basically I want to recall all items a user has in the database on the form (this bit ok) then when clicking the send button only 1 email is sent to user and 1 email sent to me with a list of all the items.
Same on thank you page - One thank you page showing list of items.
The resulting Email/thank you page should look something along the lines of:
TITLE 1 - TITLE 2 - TITLE 3 - TITLE 4 - TITLE 5
first 1 - first 2 - first 3 - first 4 - first 5
secnd 1 - secnd 2 - secnd 3 - secnd 4 - secnd 5
HERE IS THE CODE:
<table><tr>
<td>TITLE 1</td> <td>TITLE 2</td> <td>TITLE 3</td> <td>TITLE 4</td> <td>TITLE 5</td>
</tr>
<?php
$sql = "SELECT * FROM ".$TABLES["table1"]." WHERE user_id='".$_SESSION["useraccount"]."'";
$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
while ($TABLE1 = mysql_fetch_assoc($sql_result)) {
$sql = "SELECT * FROM ".$TABLES["table2"]." WHERE id='".$TABLE1["user_id"]."'";
$sql_resultT = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
$USER=mysql_fetch_assoc($sql_resultT);
?>
<?
if (isset($action)) {
$to = $USER["email"];
$mailheader = "From: $email\r\n";
$mailheader .= "Reply-To: $email\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$msg =
"
Dear ".stripslashes($USER["name"])."<br><br>
some text here
TITLE1: ".$TABLE1["name"].", - TITLE2. ".$TABLE1["something"]." etc etc for TITLE 3 4 5<br><br>
";
mail($to, "email subject", $msg, $mailheader) or die ("Failure");
mail("to-me@my-email.com", "email subject", $msg, $mailheader) or die ("Failure");
echo
"<br /><br /><font size=2><strong><center>Thank you!</center><br />
Your form has been sent:</center><br />
";
};
?>
<form action="page_this-code_is_on" method="post">
<input type="hidden" name="action" value="0">
<input type="hidden" name="id" value="<?php echo $_REQUEST["id"]; ?>">
<tr>
<td><?php echo stripslashes($TABLE1["TITLE1"]); ?></td>
<td><?php echo stripslashes($TABLE1["TITLE2"]); ?></td>
<td><?php echo stripslashes($TABLE1["TITLE3"]); ?></td>
<td><?php echo stripslashes($TABLE1["TITLE4"]); ?></td>
<td><?php echo stripslashes($TABLE1["TITLE5"]); ?></td>
</tr>
<?php } ?>
</tr>
</table>
<table width="100%"><tr>
<td align="center" valign="top"> <input type="submit" name="Submit" value="Send"></td>
</tr><tr><td></td></tr></table>
</form>
</table>
I HAVE TRIED CHANGING THE 'while' STATEMENT TO 'if' IN THE ORIGINAL CALL TO THE DATABASE BUT THIS ONLY RETURNS ONE ITEM RESULT.
REMOVE/ADDED BITS OF CODE CURLY BRACES ETC ETC - PUZZLED ?