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="[email protected]";
  $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
https://forums.phpfreaks.com/topic/121044-problem-with-an-insert-query/
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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.