I have a webpage with a form that when submitted inserts the contents of a dropdown menu and a textarea into a database.
I would also like the same info to be sent in an email.
Most of this works ok, the data from the form fields is added to the database.
However when the email is received the contents of the textarea does not show.
When the form is submitted it redirects back to itself via another page.
The code for handeling the email is also on this page.
This is the code on my form page
$query = mysql_query("INSERT INTO reportspub (name, report, date, resolved) VALUES ('$name', '$report', null, 0)") or die(mysql_error());
mysqli_query($dbc, $query);
mysqli_close($dbc);
}
$_action = 'report_confirm_pub.php';
ini_set('display_errors', 1);
error_reporting(E_ALL);
header('Location:' . $_action);
}
<form method="post" action=""><br /><div class="forms">
<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><img src="../../images/Public.png" alt="" border="0" /></td>
<td> </td>
</tr>
<tr><td align="center" valign="top"><table border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" valign="bottom"><label for="pub_access"></label><select name="pub_access" id="pub_access">
<?php
do {
?>
<option value="<?php echo $row_pub_access['name']?>"><?php echo $row_pub_access['name']?></option>
<?php
} while ($row_pub_access = mysql_fetch_assoc($pub_access));
$rows = mysql_num_rows($pub_access);
if($rows > 0) {
mysql_data_seek($pub_access, 0);
$row_pub_access = mysql_fetch_assoc($pub_access);
}
?>
</select> </td>
</tr>
</table>
</td>
<td><label for="report_pubaccess"></label>
<span id="sprytextarea1">
<textarea name="report_pubaccess" id="report_pubaccess" cols="50" rows="8"></textarea>
<span class="textareaRequiredMsg">A value is required.</span></span><br />
<input name="resolved" type="hidden" value="<?php echo $resolved_result ?>" />
</td>
</tr>
<tr>
<td></td>
<td colspan="2" align="left"><input type="submit" name="submit" id="submit" value="Submit" /></td>
</tr></table></div>
</form><br />
This is the code on my redirect (email) page
$from = 'michael.boyce@westlothian.gov.uk';
$subject = 'Public Access computer problem reported';
print "the value is".$_POST['report_pubaccess'];
//$text = $_POST['report_pubaccess'];
$dbc = mysqli_connect('127.0.0.1', 'root', 'root', 'abe') or die('Error connecting to MySQL server.');
$query = "SELECT name, user_email FROM users";
$result = mysqli_query($dbc, $query)
or die('Error querying database.');
while ($row = mysqli_fetch_array($result)){
$to = $row['user_email'];
$first_name = $row['name'];
$msg = "Dear $name,\n$text";
mail($to, $subject, $msg, 'From:' . $from);
//echo 'Email sent to: ' . $to . '<br />' . $msg;
}
mysqli_close($dbc);
$url = 'computers_publicaccess.php?' . http_build_query($_GET) ;
header('Location: ' . $url);
I tried commenting out the redirect
/ $url = 'computers_publicaccess.php?' . http_build_query($_GET) ;
header('Location: ' . $url); /
and added vardump
echo "<pre>get";
var_dump($_GET);
echo "</pre>";
echo "<pre>post";
var_dump($_POST);
echo "</pre>";
Output from vardump
getarray(0) {
}
postarray(0) {
}