Jump to content

Problem with an insert query


bravo14

Recommended Posts

Hi all

 

I have written a piece of code that will send a newsletter to a set of email addresses in a table I also wanted to insert the newsletter into a separate table

<?php
include "connect.php";
if(isset($_POST['submit']))
{
  $subject=$_POST['subject'];
  $nletter=$_POST['nletter'];
  if(strlen($subject)<1)
  {
     print "You did not enter a subject.";
  }
  else if(strlen($nletter)<1)
  {
    print "You did not enter a message.";
  } 
  else
  {
      $nletter=$_POST['nletter'];
      $subject=$_POST['subject'];
      $nletter=stripslashes($nletter);
      $subject=stripslashes($subject);
      $lists=$_POST['lists'];
      $nletter=str_replace("rn","<br>",$nletter);
  $adminmail="news@yardleyheroes.co.uk";
  $path="http://www.yardleyheroes.co.uk/newsletter";
      //the block above formats the letter so it will send correctly.
      $getlist='SELECT * FROM `email_table` WHERE `validated` = \'1\''; //select validated e-mails
      $getlist2=mysql_query($getlist) or die("Could not get list");
      while($getlist3=mysql_fetch_array($getlist2))
      {
         $headers = "From: $adminmail \r\n"; 
         $headers.= "Content-Type: text/html; charset=ISO-8859-1 ";  //send HTML enabled mail
         $headers .= "MIME-Version: 1.0 ";     
         mail("$getlist3[email]","$subject","$nletter",$headers);
      }
      print "Newsletter Sent.";
   }
}
else
{
   print "<form action='sendletter.php' method='post'>";
   print "Subject:<br>";
   print "<input type='text' name='subject' size='20' class='textbox'><br>";
   print "Message:<br>";
  include_once "includes/fckeditor/fckeditor.php";
  $oFCKeditor = new FCKeditor('nletter'); 
  $oFCKeditor->BasePath = "includes/fckeditor/"; 
  $oFCKeditor->Value    = ""; 
  $oFCKeditor->Width    = 540; 
  $oFCKeditor->Height   = 400; 
  echo $oFCKeditor->CreateHtml(); 

   print "<br><input type='submit' name='submit' value='submit' class='textbox'></form>";


}
?>

The newsletter is sent ok, but the data is not added to the table, can anyone point out what I have done wrong?

Cheers

Link to comment
Share on other sites

Hmm where is your insert query? I should be something like this:

 

<?php
while($getlist3=mysql_fetch_array($getlist2)){
     //send email
     $results = mysql_query("INSERT INTO newsletters (title, content) VALUES ('my newsletter', 'some content')") or die();
}
?>

 

Or you can place it outside of the while() loop if you want to add just a single newsletter. Is this what you wanted?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.