Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Emails not presenting mysql data.

Status
Not open for further replies.

BadChough

Programmer
Dec 20, 2007
137
GB
I have set up a page that presents data from a MYSQL dbase, and then sends the information as an email when one submits a recipient's email address. It also sends me a notification email.
As you can see below the recordset (restSelect) is selected by receipt of a POSTed numerical variable from a previous page.
The page works to the extent that the correct data is drawn from the dbase and presented on the webpage, but when the emails are sent the messages arrive without the dbase info.
I don't understand why the emails are not collecting the data. Can anyone see where I'm going wrong, please?
(php written largely by DW2004)

Here's the code:
Code:
<?php require('../../Connections/tormented3.php'); ?>
<?php
$colname_restSelect = "1";
if (isset($_POST['org_pk'])) {
  $colname_restSelect = (get_magic_quotes_gpc()) ? $_POST['org_pk'] : addslashes($_POST['org_pk']);
}
mysql_select_db($database_tormented3, $tormented3);
$query_restSelect = sprintf("SELECT * FROM cel_contents WHERE cel_pk = %s", $colname_restSelect);
$restSelect = mysql_query($query_restSelect, $tormented3) or die(mysql_error());
$row_restSelect = mysql_fetch_assoc($restSelect);
$totalRows_restSelect = mysql_num_rows($restSelect);

if(isset($_POST['send'])){ // 'submit' is the name of your submit button
$error = '';

 // process and validate a field: 
  $email1 = trim($_POST['email1']); 
 if($email1 == ''){ // if name is empty, show an error message (us that for required fields)
 $error .= '<p style="color:red;">You missed out your email address!</p>'; // error message
 }

 if($error == ''){ // if no error, process the form 

  // Mail script 
$org = $row_restSelect['cel_org'];
$tel =  $row_restSelect['cel_tel'];

$message = "Thank you for requesting information about $org.\n\n"; // Set up the email message to the client.
$message .= "Contact Details: \n";
$message .= "Tel No. $tel \n";

$inform_me = "Details of $org have been sent to $email1"; // Set up the email to inform me of the information request.
// The emails:
if(mail("$email1", $org, $message, "From: [URL unfurl="true"]www.somewhere.org.uk")[/URL] && mail("feedback@somewhere.org.uk", $org,
$inform_me, "From: [URL unfurl="true"]www.somewhere.org.uk"))[/URL]
{
header('location: [URL unfurl="true"]http://www.somewhere.org.uk/feedback/email_redirect.php');//[/URL] redirect to page if email has been successfully sent
exit;
}else{
$error == '<p style="color:red;">An error occured, your email could not be sent. Please try
again</p>';
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>Feedback  Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="fb.js"></script>
<link href="../css/mentalhealth_bx.css" rel="stylesheet" type="text/css" />
</head>
<body class="grey_bground" >

<form action="<?php echo $PHP_SELF; ?>" method="post" name="email1" id="email1">
<?php echo $error; ?>
			<!-- Call the processing routine -->
<div id="wrapper">		<!-- This div code sometimes appears red in DW because there are 2 closing /divs (see below) -->
  <table  class="whitecell" cellpadding="1">
    <tr>
      <td colspan="4" class="cellcolour"><p align="center" class="redhaed">NB. This Email Form is not yet functioning correctly </p>
        <p align="center" class="strongbody">Use this form to send the information below about <span class="redhaed"><?php echo $row_restSelect['cel_org']; ?></span> to yourself, or to someone else<br />
        by entering the relevant email address in the space below.<br />
        </p>
        </td>
    </tr>
    <tr>
      <td align="right"><p> </p>
      <p> </p></td>
      <td colspan="3" valign="top"> <?php echo $org_pk; //temporary check ?></td>
    </tr>
    <tr>
      <td align="right"><span class="right_cell">Information about</span></td>
      <td colspan="3" valign="top"><?php echo $row_restSelect['cel_org']; ?> from [URL unfurl="true"]www.somewhere.org.uk[/URL] </td>
    </tr>
    <tr>
      <td colspan="4" align="right"> </td>
      </tr>
    <tr>
      <td align="right" class="right_cell">Tel.no. </td>
      <td><?php echo $row_restSelect['cel_tel']; ?> </td>
    </tr>
    <tr>
      <td valign="top" class="right_cell"> </td>
      <td valign="top"> </td>
    </tr>
    <tr>
      <td colspan="4" valign="top"></td>
    </tr>
    <tr>
      <td align="right" class="cellcolour">
        Recipient's email address:<b> <br />
        </b></td>
      <td><input name="email1" type="text" size="40" value="" />
       <input name="send" type="submit" value="  Send  " />
      </td>
    </tr>
    <tr>
      <td colspan="2"><div align="right"></div></td>
      </tr>
  </table>
</div>
</form>
</body>
</html>
<?php
mysql_free_result($restSelect);
?>
Many thanks for looking.
Steve
 
try enquoting the %s in your variable. we do not know what value cel_pk can take. however the fact that you check it for magic quotes suggests that it is a string variable. strings must be enquoted for use in a mysql query. enquoting numerical values does no harm.

however you say that the correct data is returned from the query. Despite this statement, I suspect that something is wrong with your database code as your message code looks ok at first glance. try footprinting your data with a
Code:
 var_dump($row_restSelect);
just after the variable has been instantiated.
 
I dont see where the mysql outut is attached to the message?

i see teh form requests, data validation and form processing the results, but nothing to attach said output.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
@KarveR
Code:
$org = $row_restSelect['cel_org'];
$tel =  $row_restSelect['cel_tel'];

$message = "Thank you for requesting information about $org.\n\n"; // Set up the email message to the client.
$message .= "Contact Details: \n";
$message .= "Tel No. $tel \n";
 
Oh, I was expecting something more than just a variable, more like a whole report.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Sorry to have taken so long to acknowledge your replies, folks. I was called away unexpectedly. It emerges that I needed to add
Code:
<input type="hidden" name="org_pk" id="org_pk"
  value="<?php echo $_POST['org_pk']; ?>" />
to my form as the values of the variable were not preserved after the submission of the email form. With the extra code the page now works fine.
Thanks for your efforts,
Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top