Forum Moderators: coopster
One of the selections is to contatc seller this at the moment is set to a mailto HTML command which is not good considering that it gives everyones email address away at the moment.
I am trying to build a bit of script that will get the id from the classified then open another page which will pull all the information off of the MYSQL databse I can do this but executing the mail () command is slightly more harder for me the script works until you press submit and then loads the page again (form action="post") this is where the code ceases. Below is the code please tell me what I am doing wrong.
<?
// error handling
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
require_once ('../includes/connect.php');
// 20th August 2004 - Changed $get var to $id also changed row email to $mail. Put in header for email sent
// Define the query
$query = "SELECT * FROM diecast_sale WHERE item_no={$_GET['id']}";
if ($r = mysql_query ($query)) { // Run the query
$mail = $row['email'];
$row = mysql_fetch_array ($r);
mysql_close(); // Close the db connection
} else {
print "<p>Could not retrive the entry because: <b>" . mysql_error() . "</b>. The query was $query.</p>";
}
if ( isset ($_POST['submit'])) {
$problem = FALSE; // No problems so far.
// Check for each value.
if (empty ($_POST['username']) ) {
$problem = TRUE;
print '<p><font color="red">Please enter your name or your username!</font></p>';
}
if (empty ($_POST['email'])) {
$problem = TRUE;
print '<p><font color="red">Please enter your email address!</font></p>';
}
if (empty ($_POST['enquiry']) ) {
$problem = TRUE;
print '<p><font color="red">Please enter an enquiry!</font></p>';
}
if (!$problem) {
// send the email
$body = "Question from {$_POST['username']}. enquiry {$_POST['enquiry']}. From Email {$_POST['email']}.";
if (@mail ($mail , 'Enquiry from NDUK user!' , $body )) {
print '<p align="center"><b>Thank you for your enquiry!</b></p>';
}
} else {
print '<p><font color="red">Please try again!</font></p>';
}
} // End of handle form
// Make the form
print' <form action="contactseller.php" method="post">
<table width=100% cellpadding=5 cellspace=5 border=0 bgcolor=#e3e3e3 align="center">
<tr>
<td valign="top">Your Username:</td>
<td valign="top">
<div align="left">
<input type="text" name="username" size="20" />
</div>
</td>
</tr>
<tr>
<td valign="top">Your Email Address:</td>
<td valign="top">
<div align="left">
<input type="text" name="email" size="40" />
</div>
</td>
</tr>
<tr>
<td valign="top">Enquiry:</td>
<td valign="top">
<div align="left">
<textarea name="enquiry" cols="50" rows="10"></textarea>
</div>
</td>
</tr>
<tr>
<td valign="top"></td>
<td valign="top">
<div align="left">
<input type="hidden" name="id" value="' . $GET['id'] . '" />
</div>
</td>
</tr>
<tr>
<td valign="top"></td>
<td valign="top">
<div align="left">
<input type="submit" name="submit" value="Send your question!" />
</div>
</td>
</tr>
</table>
</form>';
?>
You have entered: ( value="'.$GET['id'].'" )
I think you may mean: ( value="'.$_GET["id"]."'" )
That is enough to cause the form to NOT display, even though the mail is sent successfully, several lines earlier in the script.
this bit looks suspect
$query = "SELECT * FROM diecast_sale WHERE item_no={$_GET['id']}";
if ($r = mysql_query ($query)) { // Run the query
$mail = $row['email'];
$row = mysql_fetch_array ($r);
the lines are a little mixed up there, try it this way
$query = "SELECT * FROM diecast_sale WHERE item_no={$_GET['id']}";
$r = mysql_query ($query) or die (mysql_error());
$numrows = mysql_num_rows($r);
if ($numrows < 1) {
$problem = TRUE;
print '<p><font color="red">Could not find the email address</font></p>';
} else if ($numrows > 1) {
$problem = TRUE;
print '<p><font color="red">More than one record found</font></p>';
} else {
mysql_data_seek($r,0);
$row = mysql_fetch_array($r);
$mail = $row['email'];
} I added in the numrows to check that only one row is returned just in case. Maybe that will help give us a better idea where the problem is.
When you click the submit button the browser reloads the page because of the form action part (Is this required?) but when the page reloads I get an error saying:-
There is a problem with your MYSQL syntax this is because the id has not carried over so there is an immedate error
I grab the id from the classified that is tehn picked up by this code. Have I got in the wrong order should the
if (isset submit part go first?
I am really confused am I making harder work for myself.
I appreciate all the help you are giving me
$mail = $row['email'];
but you are doing it in the wrong place and there would be no value assigned to that var given the code that you posted.
You need to diagnose the reason for the mail not getting sent. Start with the values that you are passing to the mail function to see if you are assigning values properly. If they are all correct then you look at mail malfunctions after that.