On 10/10/05, Richard Lynch [EMAIL PROTECTED] wrote:
$email_body is a free form text field, and he wants to be able to type
in anything he desires and have it pulled from the contact table.
Firstly please accept my aplogies for the deay in responding to your
questions, I;ve had the most terrible flu.
pseudo code (ish), as I've completely bastardised what I had when I
posed the question.
// insert newsletter into newsleter_tbl in database ...
from a form, body in a textarea field, client wants to type in
whatever he likes with database column names as varibles, eg $email,
$first_name
this is the newsletter write on newsletter_new.php
if ($submit){
// removed error checking etc
$email_subject = htmlentities(addslashes($email_subject));
// tried various combintions of htmlentities, addslashes and nothing
when writting field to DB
if ($email_style == 1){
$email_body = htmlentities(addslashes($email_body));
}else{
$email_body = addslashes($email_body);
}
$email_style = htmlentities(addslashes($email_style));
$query = INSERT INTO newsletters_tbl (email_subject, email_body,
email_date, email_style) VALUES ('$email_subject', '$email_body',
NOW(), '$email_style');
if ($result = mysql_query($query, $connection)) {
$newsletter_id= mysql_insert_id($connection);
print (pbSuccess/b Add newsletter (# $newsletter_id)
successful. /p\n);
print (pa
href=\newsletter_test.php?this_nid=$newsletter_idamp;sid=$sidamp;page=$page\CLICK
HERE TO TEST/td/p\n);
} else {
printf (pbError: %s\n, mysql_errno () . /bbr);
printf (%s\n, mysql_error () . br);
print ($query/p\n);
}
}
}
// BTW the contact details are in another table in database already.
// Sending out the newsletter
$nquery= SELECT c.id, first_name, email FROM contact_tbl c LEFT OUTER
JOIN newsletters_contacts_tbl nct ON nct.contact_id =c.id AND
newsletter_id = '$this_nid' WHERE nct.contact_id IS NULL AND
newsletter = '$email_style' GROUP BY email LIMIT 1;
if ($nresult = mysql_query($nquery, $connection)){
if (mysql_num_rows($nresult) 0){
while ($myrow = mysql_fetch_row($nresult)) {
$uid=$myrow[0];
$first_name=stripslashes($myrow[1]);
$email=stripslashes($myrow[2]);
$query = SELECT * FROM newsletters_tbl WHERE id = '$this_nid' ;
$result = mysql_query($query, $connection);
if($result){
while ($myrow = mysql_fetch_row($result)){
$newsletter_id = $myrow[0];
$email_subject = stripslashes($myrow[1]);
$email_body = stripslashes($myrow[2]);
$email_date = $myrow[3];
$email_style = $myrow[4];
$email_status = $myrow[5];
}
if ($email_status == 0){
print (pRequires Confirmation/p);
}elseif($email_status == 1){
/*
// NOW USING {{ }} as in many templating systems
// so familar to those sorts of users.
// would prefer if I could just use $columnName from
// contact_tbl.
// Why doesn't it just know the var as we've already
// got it above...?
*/
$email_body = ereg_replace (\{\{uid\}\}, $uid, $email_body);
$email_body = ereg_replace (\{\{email\}\}, $email, $email_body);
$email_body = ereg_replace (\{\{first_name\}\},
$first_name, $email_body);
if ($email_style == 1){
// INSERT PLAIN TEXT HEADER
}elseif ($email_style == 2){
// INSERT HTML MIME HEADERS
}
$outquery=INSERT INTO newsletters_contacts_tbl
(newsletter_id, contact_id, sent_date) VALUES ('$newsletter_id',
'$uid', NOW());
if ($outresult = mysql_query($outquery, $connection)) {
// SEND IT CODE
} else {
// ERROR CODE
}
}
}
}
}else{
// ERROR CODE
}
Many thanks for your help on this mater.
--
Kind regards,
Liam
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php