PHP - Sending Emails Using Array Values
I have a form that allows a user to select from several dropdowns, employees who will receive an email message.
The email script works fine, however if an employee is selected more than once (which is not a rare) then the employee will receive as many email messages as their name appears. I would like for each employee to only receive the email once. For example: I am the submitter of the form and I am also the coordinator for this particular job. Therefore, my name & email are in the array twice and I will receive two emails on submit. Here is my email script: Code: [Select] $submitter = get_employee_email($user_id); $project_manager = get_employee_email($pm_id); $accountant = get_employee_email($a_id); $coordinator = get_employee_email($pc_id); $contractor = get_employee_email($contractor_id); $director = get_employee_email($dr_id); $to = array($submitter, $project_manager, $accountant, $coordinator, $contractor, $director); foreach ($to as $t){ $headers["From"] = "TEST <TEST@gmail.com>"; $headers["To"] = $t; $headers["Subject"] = "TESTING FOR JOB ID $job_id"; $text = "TESTING. Please review!"; $html = "<html><body>TESTING. Please review!</body></html>"; $file_path = "./$file"; $crlf = "\n"; $name = "TEST.csv"; $smtp_info["host"] = "TEST@gmail.com"; $smtp_info["port"] = "40"; $mime = new Mail_mime($crlf); $mime->setTXTBody($text); $mime->setHTMLBody($html); $content_type = "text/csv"; $mime->addAttachment($file_path, $content_type, $name); $body = $mime->get(); $hdrs = $mime->headers($headers); $SMTP = Mail::factory('smtp',$smtp_info); $mail = $SMTP->send($t, $hdrs, $body); } Similar TutorialsHi guys, I am using following code for sending out confirmation email after successful transaction to the user. But, I users are not getting any confirmation emails. Can somebody help me out here. May be I am doing wrong in "$to" function as $sender_email is at previous form, So how can I use Session here? If I am wrong here? Any someone help? Many Thanks in advance. $to = "$sender_email"; $subject = "Your Transaction"; $headers = "From: Company <company@abc.com>\n"; $headers .= "Reply-To: Company <company@abc.com>\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n"; $message = "Dear ".$rs["sender_name"].", ".$_email_nl.$_email_nl; $message .= "Your paid amount ".$amount." ".$rs["currency"]." has been added to desired account.".$_email_nl.$_email_nl; $message .= "Regards,"; $message .= "my company"; mail($to, $subject, $message, $headers); Hi, Just wondering if you can figure out why this code is sending two emails?? I can't figure it out. <?php $recent=$_GET['recent']; $sendemail=$_GET['sendemail']; mysql_close($conn); $output = 'no'; $dbhost = '*********'; $dbuser = '*********'; $dbpass = '*********'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('MYSQL N/A - Please Contact Admin'); $dbname = 'documentaries'; mysql_select_db($dbname); $query1 = "SELECT * FROM table1"; $result1 = mysql_query($query1); $num1 = mysql_numrows($result1); if(is_int($num1/10)){ $output = 'yes'; } if (($output == 'yes') && ($sendemail == 'yes')) { $query2 = "SELECT * FROM table2"; $result2 = mysql_query($query2); $num2 = mysql_numrows($result2); $i=0; while ($i < $num2) { $email=mysql_result($result2,$i,"email"); $subject = "Subject Here"; $msg = "Message Here"; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; $eLog="/tmp/mailError.log"; //Get the size of the error log //ensure it exists, create it if it doesn't $fh= fopen($eLog, "a+"); fclose($fh); $originalsize = filesize($eLog); mail($email,$subject,$msg,$headers); /* * NOTE: PHP caches file status so we need to clear * that cache so we can get the current file size */ clearstatcache(); $finalsize = filesize($eLog); //Check if the error log was just updated if ($originalsize != $finalsize) { print "<b>Problem sending mail to $email. (size was $originalsize, now $finalsize) See $eLog...<br>"; } else { print "Mail sent $email<br>"; } $i++; } // redirect } mysql_close($conn); // redirect ?> Thanks For your help! Hey guys! Been a long time since I've posted here but I am back for help because I'm encountering a problem that's kind of baffling me. I'm programming a web game, and one of the things that happens is that an email gets sent out when it's your turn in one of your games. This is working fine and all but I can not for the life of me figure out how to send email with html in it that is universally accepted. What I've been doing so far works for gmail, hotmail, etc. but for some reason breaks entirely when someone opens an email with a client like Thunderbird or Outlook. Here's what I've been doing: $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: Admin <admin@examplesite.com>' . "\r\n"; $mail_body = '<html><body>It is now your turn in the game. The game can be viewed <a href="examplesite.com">here</a>.</body></html>'; mail("user@examplesite.com",'New Turn',$mail_body,$headers); Is there something I'm missing? I have literally no experience using Outlook or the like so I don't know if it's a problem with them or if I'm doing something wrong. I'm having an issue with sending HTML Emails. Here is my code, but nothing comes out right when it gets emailed. And my email client is set to view HTML. I can view other HTML emails just fine, but not these. Here is my code to send the email, just wondering whats wrong with it. Thanks for any suggestions. Code: [Select] $full_email = $frm_to . '@scotthermanfitness.com'; //define the receiver of the email $to = $full_email; //define the subject of the email $subject = 'Form Submit - SHF ' . $to_text . ' (' . $frm_name . ')'; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); //define the headers we want passed. Note that they are separated with \r\n $headers = "From: " . $frm_email . "\r\nReply-To: " . $frm_email; //add boundary string and mime type specification //$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; $headers .= " Content-type: text/html\r\n"; //begin of HTML message $message = $frm_content; //send the email $mail_sent = @mail( $to, $subject, $message, $headers ); Hi -- I'm receiving two emails with this code.. one from "webmaster" and another from "serveradmin." What's odd is that the one from serveradmin contains the subject, but not the message. Does anyone know why this is happening and how to fix it so I only receive one email? thanks -- here's the code $usercheck = $_SESSION['user_id']; $check = mysql_query("SELECT * FROM articles WHERE art.id = '$_GET[id]' AND art.user_id = '$usercheck'")or die(mysql_error()); $check2 = mysql_num_rows($check); $recep = "me@gmail.com"; $subject = "Email Subject Line"; $text = "$usercheck"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/plain; charset=UTF-8\r\n"; $headers .= "Reply-to: me@gmail.com\n"; $headers .= "X-Mailer: PHP\n"; if ($check2 != 1) { include_once ("nav_my_account.inc"); mail("$recep","$subject","$text","$headers"); $content = "<p>You can only edit your own articles. <br><br>If you feel you're getting this message in error, it may be that your session has timed out and you need to log back in. </p>\n"; } else { include_once ("nav_my_account.inc"); .....etc.... Hello, I'm trying to send an email with a PDF attachment. The email is sending, but the attachment will not open. Any help you can give is appreciated. Code snippets below: function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) { $file = $path.$filename; $file_size = filesize($file); $handle = fopen($file, "r"); $content = fread($handle, $file_size); fclose($handle); $content = chunk_split(base64_encode($content)); $uid = md5(uniqid(time())); $name = basename($file); $header = "From: ".$from_name." <".$from_mail.">\r\n"; $header .= "Reply-To: ".$replyto."\r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; $header .= "This is a multi-part message in MIME format.\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $header .= $message."\r\n\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-Type: application/pdf; name=\"".$filename."\"\r\n"; // use different content types here $header .= "Content-Transfer-Encoding: base64\r\n"; $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; $header .= $content."\r\n\r\n"; $header .= "--".$uid."--"; if (mail($mailto, $subject, "", $header)) { print("mail send ... OK"); // or use booleans here } else { print("mail send ... ERROR!"); } } $my_file = "Adol_Packet_v2.pdf"; $my_path = $_SERVER['DOCUMENT_ROOT']."/homepages/35/d350375870/htdocs/html/"; $my_name = "Company Name"; $my_mail = "atheneris@yahoo.com"; $my_replyto = "atheneris@yahoo.com"; $my_subject = "Welcome Email From Carlock & Associates"; $my_message = "Test Message"; mail_attachment($my_file, $my_path, $email_to, $my_mail, $my_name, $my_replyto, $my_subject, $my_message); I am using PHP Mailer to send out emails to an array of email address. So I am looping through the array of emails and then sending out the emails individually. The script works except it is sending out more than one email to some of the email address. Today my client told me that he got 2 more emails on Sunday just like the 2 he got on Thursday. I am assuming that this has something to do with caching, but I do not know. The trigger that sends out the emails is part of a cron job. The cronjob runs every 30 minutes. Checks to see if there is a new entry in one of the tables in the database. Then it sends out the email to all of the members. After the email is sent a value is changed for that entry in the data base. I am explaining this only to help you to see that the problem is not that the code is being triggered again. If that was the problem then there would be and email every 30 minutes and that is not what happened. Here is the code: <?php require_once('library/PHPMailer/class.phpmailer.php'); require_once('library/PHPMailer/class.smtp.php'); foreach($organizationemails as $key => $value){ $contents = '<body> <div> <p> ...content of email ... </p> </div> </body>'; error_reporting(E_ALL); error_reporting(E_STRICT); $mail = new PHPMailer(); $body = $contents; $body = preg_replace('/[\]/','',$body); $mail->IsSMTP(); $mail->Host = "ssl://smtp.mysite.org"; $mail->SMTPAuth = true; $mail->Port = 465; $mail->Username = "sendingmail@mysite.org"; $mail->Password = "password"; $mail->SetFrom('info@mysite.org', 'My Organization'); $mail->AddReplyTo('info@mysite.org', 'My Organization'); $mail->Subject = 'My Email Title'; $mail->AltBody = '... has been posted...'; $mail->MsgHTML($contents); $address = $value; $mail->AddAddress($address); if(!$mail->Send()) { echo "Message could not be sent. <p>"; echo "Mailer Error: " . $mail->ErrorInfo; exit; }else{ echo "Message has been sent to ".$value; } } ?> Hi, I am using the phpmailer class and a little script I found online, I have a form with a textarea called "plain" which submits and takes the action through to this page: Code: [Select] <?php #include PHPMailer class and database connection include("class.phpmailer.php"); include("connect.php"); #remove slashes from content $plain = stripslashes($_POST["plain"]); #initiate PHPMailer class $mail = new PHPMailer(); #set the from e-mail address $mail->From = "email@email.com"; #set the from name $mail->FromName = "myname"; #the subject of the email $mail->Subject = "Our Newsletter"; #the HTML content of the email $mail->Body = $plain; #loop through e-mail addresses $query = "SELECT email FROM member"; $result = mysql_db_query ("define_pete", $query); while ($myrow = mysql_fetch_array($result)){ #add subscribers address as the recipient $mail->AddAddress($myrow["fldEmail"]); #sends the newsletter $mail->Send(); #clears the recipient address $mail->ClearAddresses(); } ?> It gives no errors and goes through, yet it definitely sends no emails out, I have made sure the emails are correct in the field email in the table member but it is, anyone got any clue what is going wrong? Appreciated I handle MySQL errors like this:
function handle_error($err) { throw new Exception($err); } try { $con = mysql_connect("", "", "") or handle_error("mysql_connect failed! "); mysql_select_db("") or handle_error("mysql_select_db failed! "); $sql = "SELECT blah blah blah ..."; $result = mysql_query($sql, $con) or handle_error("mysql_query failed! "); } catch(exception $e) { // Log error in error_log file. trigger_error($e->getMessage() . mysql_error(), E_USER_WARNING); // Send yourself an email. error_log($e->getMessage() . "Date: " . date("l jS \of F, Y, h:i:s A") . ". File: " . $_SERVER['REQUEST_URI'], 1, "example@aol.com", "From: example@yahoo.com"); } if(isset($result)) { blah blah blah ... }The problem is, I can receive a huge number of e-mails whenever there's a connection error. How can I limit the number of e-mails that I send myself in the event that my database fails? I really haven't a clue. The only idea that I had was store the time that I sent the first e-mail in a database and then check the database before sending any other e-mails. But this obviously won't work because MySQL won't be working. Any ideas will be much appreciated. So far I just want a basic structure, a database with one table with two values, yes or no. yes would be for email validated, no for email not validated. i just want it so when a user signs up, it sends a unique link to their email to validate their email. I cant even think right now, ive been coding all day and cant even begin to think of how to start this. anybody got any ideas? thanks Hello, I'm using phpmailer for this job, and what I want is that in first mail user gets only text and in second he gets text with attachment. But code below is only sending me the mail with attachment(second mail), what is cosing this problem? Here's the code Code: [Select] for ($i=0; $i<2; $i++) { if (!class_exists("phpmailer")) { require("PHPMailer/class.phpmailer.php"); } if ($price != 0 ) { $mail = new PHPMailer(); $mail->CharSet = 'UTF-8'; $mail->From = "domain@d.com"; $mail->FromName = "Company"; $mail->AddAddress($email, ""); $mail->WordWrap = 50; $mail->IsHTML(true); $mail->Subject = "Subjcet"; $mail->Body = $content; } if ($i == 1 || $price == 0 ) { //require("PHPMailer/class.phpmailer.php"); $mail = new PHPMailer(); $mail->CharSet = 'UTF-8'; $mail->From = "domain@d.com"; $mail->FromName = "Company"; $mail->AddAddress($email, ""); $mail->WordWrap = 50; $mail->IsHTML(true); $mail->Subject = "Subjcet"; $mail->Addattachment ("file/patch".$fileName, ); // patch and name of an attachment } } I'm curious about the mechanics of the script execution here. One page in my project sends out batch emails to all users who are registered. That part is simlple enough, but in order to do it, my page has to connect to a remote SMTP server and then submit all the recipients and messages. This process can take a little bit of time, usually 5 seconds or so. If the user hits the stop button or navigates away while my script is still executing, will it mess up the emails that are being sent? If so, what other way should I restructure my script to make it more robust? The first thing that comes to my mind is adding them to some sort of queue in the database and then have a separate script that checks periodically for messages that need to be sent and then send them. The only way to do this, though, would be to make a script designed to be called by cron, and that somewhat complicated the installation of my script which I'd like to avoid. I've been ALL over the internet trying to find complete step by step guides on getting php to work for my contact form and I can't find anything. Or at least nothing that makes sense to me. I know nothing about PHP, I'm more of a designer/html/css person. PHP is completely foreign to me and very hard to understand. I have downloaded PHPMailer but I have no idea what I'm supposed to do with it or how to really configure it. I really need help in that area. This contact form is the last thing I need before I can put my redesign of my website up.
I am trying to write a program that sends out a newsletter but I am lost at returning an array of emails. This is what I have
<?php require("../PHPMailer/class.phpmailer.php"); include 'includes.php'; $mail = new PHPMailer; $subject = $_POST['subject']; $text = $_POST['newsletterBody']; $unsubscribe = "<br /><br /><br /><br />If you would no longer like to receive these emails, please <a href='removeemail.php'>Click Here</a> to unsubscribe."; $mail->IsSMTP(); // Set mailer to use SMTP $mail->Host = 'localhost'; // Specify main and backup server $mail->Port = '465'; $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = '****EMAIL ADDRESS****'; // SMTP username $mail->Password = '****EMAIL PASSWORD*****'; $mail->SMTPAuth = true; $mail->SMTPSecure = 'ssl'; // Enable encryption, 'ssl' also accepted $mail->From = '****EMAIL ADDRESS****'; $mail->FromName = '****NAME****'; $mail->AddAddress('****EMAIL ADDRESS****', '****NAME****'); $email = getEmail("", $DBH); foreach ($email as $newEmail) { $addEmail = $newEmail['email_addr']; $mail->AddAddress($addEmail); $DBH = null; } $mail->AddReplyTo('****EMAIL ADDRESS****', '****NAME****'); $mail->WordWrap = 50; // Set word wrap to 50 characters $mail->IsHTML(true); // Set email format to HTML $mail->Subject = $subject; $mail->Body = $text . "<br /><br /><br /> To unsubscribe to this email please <a href='www.raven-consult.com/newsletter_remove.php'>Click Here</a>"; $mail->AltBody = $text; if(!$mail->Send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; exit; } echo "Message has been sent <a href='newsletter.php'>Return back</a>"; ?>This is the portion of the includes file that you need to know. function getEmail($inId, $DBH) { if (!empty($inId)) { $blogstmt = $DBH->prepare("SELECT email_addr FROM newsletter_emails WHERE id = :userId"); $blogstmt->bindParam(":userId", $inId); $blogstmt->execute(); $postArray = $blogstmt->fetchAll(PDO::FETCH_ASSOC); } else { $blogstmt = $DBH->prepare("SELECT * FROM newsletter_emails"); $blogstmt->execute(); $postArray = array(); $results = $blogstmt->fetchAll(PDO::FETCH_ASSOC); foreach($results as $row){ $myPost = new nlEmails($row['id'], $row['email_addr'], $DBH); array_push($postArray, $myPost); } } return $postArray; $DBH = null; } class nlEmails { public $id; public $email; function __construct($inId=null, $inEmail=null, $DBH) { if(!empty($inId)) { $this->id = $inId; } if(!empty($inEmail)) { $this->email = $inEmail; } } }When I try and submit the newsletter to be sent out all I get back is this error. "Cannot use object of type nlEmails as array ......" Hey all, What I want to do is send an array of PHP values into a variable I created in Javascript. PHP code: <? $result = mysql_query("SELECT A,B FROM USS"); $num_rows = mysql_numrows($result); for($i = 0; $i < $num_rows; $i++) { $nome_utilizador = mysql_fetch_row($result); $user = $nome_utilizador[0] . " ". $nome_utilizador[1]; $teste[] = $user; } ?> Then, right after this PHP code, i have the following JS code: <script type="text/javascript"> var contacts = [ {name:"<? echo $teste[0]?>",email:"ccc@ddd.com"}, {name:"fff",email:"fff@ccc.com"}]; </script> I managed to get one value printed into the var, but what I want is to create a cycle, inside the JS code, that would get all the values from my $teste[] array, and print it into the var I created. Hope I made myself explicit Thanks, Ruben HI, I am trying to use pagination on the record getting displayed into the table and there's restriction on record that at a time total 15 records can be displayed and others will be displayed by clicking on NEXT (on which i did the following coding). In my SQL query 'where' clause there is select * from db where status = $query Code: [Select] <?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>?id=<?php echo $yes;?>">Next</a> <?php } // Show if not last page ?> The problem that i am facing is when i click on next then the $query gets equal to null which results to showing no record into the table kindly help how can i modify the above code so the previous value present in $query doesn't get NULL by clicking on next and show next 15 records sucessfully??? NOTE: The main purpose of the above mentioned code is to show next 15 records (which works fine if $query != NULL). I've used a lot of solutions from this site, however, this is my first post, so go easy on me :-) I've created a product form the successfully INSERTS data to a mysql table. I can successfully query the data so that product information can be updated. When I click submit to UPDATE the rows, everything updates except for 2 fields that are arrays. Here is my product form that populates data to be edited. Code: [Select] <?php session_start(); require("config.php"); require("db.php"); require("functions.php"); if(isset($_SESSION['SESS_ADMINLOGGEDIN']) == FALSE) { header("Location: " . $config_basedir); } if(isset($_GET['func']) == TRUE) { if($_GET['func'] != "conf") { header("Location: " . $config_basedir); } $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir); header("Location: " . $config_basedir . "adminedit.php"); } else { require("header.php"); $sql = "SELECT * FROM products WHERE id = " . $_GET['id'] . ";"; $query = mysql_query($sql); while ($prodrow = mysql_fetch_array($query)){ $id = $prodrow['id']; $active=$prodrow['active']; $cat_id=$prodrow['cat_id']; $name=$prodrow['name']; $description=$prodrow['description']; $details=$prodrow['details']; $price=$prodrow['price']; $price2=$prodrow['price2']; $price3=$prodrow['price3']; $price4=$prodrow['price4']; $price5=$prodrow['price5']; $price6=$prodrow['price6']; $minimum=$prodrow['minimum']; $price7=$prodrow['price7']; $price8=$prodrow['price8']; $price9=$prodrow['price9']; $image=$prodrow['image']; } ?> <form action="adminprodupdate.php" method="post"> <table width="500" border="1" cellpadding="10"> <tr> <td>ID:</td> <td><input type="hidden" value="<? echo $id; ?>" name="id" /></td> </tr> <tr> <td>Active:</td> <td><input name="active" type="radio" value="0" <?php echo ($active=='0')? 'checked':'';?> />Yes<br /> <input name="active" type="radio" value="1" <?php echo ($active=='1')? 'checked':'';?> />No</td> </tr> <tr> <td>Category:</td> <td><input name="cat_id" type="radio" value="1" <?php echo ($cat_id=='1')? 'checked':'';?> />Hats<br /> <input name="cat_id" type="radio" value="2" <?php echo ($cat_id=='2')? 'checked':'';?> />Shirts<br /> <input name="cat_id" type="radio" value="3" <?php echo ($cat_id=='3')? 'checked':'';?> />Promotional Items</td> </tr> <tr> <td>Product ID: </td> <td><input type="text" name="name" value="<? echo $name; ?>"></td> </tr> <tr> <td>Short Description: </td> <td><input type="text" name="description" value="<? echo $description; ?>"></td> </tr> <tr> <td>Details:</td> <td><textarea name="details" cols="50" rows="10" ><? echo $details; ?></textarea></td> </tr> <tr> <td>Price for S-XL:<br /> <br /><strong><div id="redfont">**Shirts**<br />&<br />**Hats**</div></strong></td> <td>1-23: <input type="text" name="price" value="<? echo $price; ?>"><br><br> 24-47: <input type="text" name="price2" value="<? echo $price2; ?>"><br><br> 48+: <input type="text" name="price3" value="<? echo $price3; ?>"><br><br> </td> </tr> <tr> <td>Price for 2XL - 5XL:<br /> <br /><strong><div id="redfont">**Shirts ONLY!**</div></strong></td> <td>1-23: <input type="text" name="price4" value="<? echo $price4; ?>"><br><br> 24-47: <input type="text" name="price5" value="<? echo $price5; ?>"><br><br> 48+: <input type="text" name="price6" value="<? echo $price6; ?>"><br><br> </td> </tr> <tr> <td>Minimum QTY: </td> <td><input type="text" name="minimum" value="<? echo $minimum; ?>"></td> </tr> <tr> <td>Sizes:</td> <td><? echo ''; $result = mysql_query("SELECT * FROM sizes"); while ($row = mysql_fetch_assoc($result)) { $selected = ''; $result2 = mysql_query("SELECT * FROM productoptions WHERE productid = '" . $_GET['id'] . "' AND sizeid = '" . $row['id'] . "'"); if ($row2 = mysql_fetch_assoc($result2)) { $selected = 'checked '; } echo '<input type="checkbox" name="size[]" value="' . $row['id'] . '" ' . $selected . '/> ' . $row['size'] . '<br />'; } ?> </td> </tr> <tr> <td>Colors:</td> <td><? $result = mysql_query("SELECT * FROM colors"); while ($row = mysql_fetch_assoc($result)) { $selected = ''; $result2 = mysql_query("SELECT * FROM productoptions WHERE productid = '" . $_GET['id'] . "' AND colorid = '" . $row['id'] . "'"); if ($row2 = mysql_fetch_assoc($result2)) { $selected = 'checked '; } echo '<input type="checkbox" name="color[]" value="' . $row['id'] . '" ' . $selected . '/> ' . $row['color'] . '<br />'; } ?> </td> </tr> <tr> <td> </td> <td><input type="Submit" value="Update this product"></td> </tr> </form> </table> <?php } require("footer.php"); ?> Here is my script: Code: [Select] <?php include("config.php"); include("db.php"); $id=$_POST['id']; $active=$_POST['active']; $cat_id=$_POST['cat_id']; $name=$_POST['name']; $description=$_POST['description']; $details=$_POST['details']; $price=$_POST['price']; $price2=$_POST['price2']; $price3=$_POST['price3']; $price4=$_POST['price4']; $price5=$_POST['price5']; $price6=$_POST['price6']; $minimum=$_POST['minimum']; $arrsizes = $_POST['size']; $arrcolors = $_POST['color']; $image=$_POST['image']; $sql="UPDATE products SET active = '$active', cat_id = '$cat_id', name = '$name', description = '$description', details = '$details', price = '$price', price2 = '$price2', price3 = '$price3', price4 = '$price4', price5 = '$price5', price6 = '$price6', minimum = '$minimum', image = '$image' WHERE id = '$id'"; $result = mysql_query("SELECT id FROM products ORDER BY id DESC LIMIT 0,1"); if ($row = mysql_fetch_assoc($result)) { $productid = $row['id']; } foreach ($arrsizes as $sizevalue) { foreach ($arrcolors as $colorvalue) { $sql2="UPDATE productoptions SET sizeid = '$sizevalue', colorid = '$colorvalue' WHERE productid='$id' "; } } mysql_query($sql) or die ("Error: ".mysql_error()); mysql_query($sql2) or die ("Error: ".mysql_error()); echo $sql; echo $sql2; header("Location: " . $config_basedir . "adminhome.php"); ?> And here is what is echo'd after submit: Code: [Select] UPDATE products SET active = '0', cat_id = '2', name = 'Test Edit Prod', description = 'just a simple test', details = 'just a simple testjust a simple testjust a simple testjust a simple testjust a simple testjust a simple test', price = '1', price2 = '2', price3 = '3', price4 = '4', price5 = '5', price6 = '6', minimum = '127', image = '' WHERE id = '41'UPDATE productoptions SET sizeid = '6', colorid = '5' WHERE productid='41' This part of the code: UPDATE productoptions SET sizeid = '6', colorid = '5' WHERE productid='41' , is supposed to be updating sizes and colors, however, it is only updating the last size/color selected in the check box. Thanks in advance for any support! This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=350049.0 Hello, recently I changed host of my website and when a visitor clicks "contact us" button in my website (in which one needs to enter his/ her email, name, phone , etc) and submit his/her message then I get email. Before this hosting I used to get emails from the visitor who filled the form so it was easier for me to reply but now after I changed the host I get email as "mydomain@hosting-company-domain" instead of the visitor's email. I messaged them then they told me something about SMTP authenticate using PHP, please guide me to fix this. Hi all, I'm a first time poster here and I would really appreciate some guidance with my latest php challenge! I've spent the entire day googling and reading and to be honest I think I'm really over my head and need the assistance of someone experienced to advise the best way to go! I have a multi dimensional array that looks like (see below); the array is created by CodeIgniter's database library (the rows returned from a select query) but I think this is a generic PHP question as opposed to having anything to do with CI because it related to working with arrays. I'm wondering how I might go about searching the array below for the key problem_id and a value equal to a variable which I would provide. Then, when it finds an array with a the matching key and variable, it outputs the other values in that part of the array too. For example, using the sample data below. How would you recommend that I search the array for all the arrays that have the key problem_id and the value 3 and then have it output the value of the key problem_update_date and the value of the key problem_update_text. Then keep searching to find the next occurrence? Thanks in advance, as above, I've been searching really hard for the answer and believe i'm over my head! Output of print_r($updates); CI_DB_mysql_result Object ( [conn_id] => Resource id #30 [result_id] => Resource id #35 [result_array] => Array ( ) [result_object] => Array ( ) [current_row] => 0 [num_rows] => 5 [row_data] => ) Output of print_r($updates->result_array()); Array ( [0] => Array ( [problem_update_id] => 1 [problem_id] => 3 [problem_update_date] => 2010-10-01 [problem_update_text] => Some details about a paricular issue [problem_update_active] => 1 ) [1] => Array ( [problem_update_id] => 4 [problem_id] => 3 [problem_update_date] => 2010-10-01 [problem_update_text] => Another update about the problem with an ID of 3 [problem_update_active] => 1 ) [2] => Array ( [problem_update_id] => 5 [problem_id] => 4 [problem_update_date] => 2010-10-12 [problem_update_text] => An update about the problem with an ID of four [problem_update_active] => 1 ) [3] => Array ( [problem_update_id] => 6 [problem_id] => 4 [problem_update_date] => 2010-10-12 [problem_update_text] => An update about the problem with an ID of 6 [problem_update_active] => 1 ) [4] => Array ( [problem_update_id] => 7 [problem_id] => 3 [problem_update_date] => 2010-10-12 [problem_update_text] => Some new update about the problem with the ID of 3 [problem_update_active] => 1 ) ) |