troubleshooting Question

Suppress comment field in submitted PHP form if it's blank

Avatar of kmurphychi
kmurphychi asked on
2 Comments1 Solution254 ViewsLast Modified:
I have a form that people fill out to send a product to their friend.  I would like to be able to suppress the comment field being included if it is left blank by the user.   Thanks for any help!  Below is the code:

if(isset($_POST["_task"]) && $_POST["_task"]=="SEND"){
$sender = $_POST['sender'];
$comment = $_POST['comment'];

$subject = "subject";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'From: email' . "\r\n";

for($i = 1; $i <=4; $i++) {
$r_email = "email_".$i;
$email = $_POST[$r_email];

if($r_email != "email_") {

$message='<p style="width:450px; font-family:arial; font-size:18px;color:#717783;">These photos are being sent to you at the request of '.$sender.'</p><p style="width:450px; font-family:arial; font-size:18px;color:#717783;">'.$comment.'</p><table style="width:450px; font-family:arial; font-size:18px;color:#717783;" border="0" width="480" cellspacing="0" cellpadding="0"><tr>';
$sql = mysql_query("select p.productid,pd.productname,pd.price,pd.description,pd.thumb from products p , products_description pd where pd.productid = p.productid and p.productid = $id");
$row = mysql_fetch_row($sql);
$productname= str_replace(" Collection", "", $productname);

$menu_id      = $_GET['menulevel'];
$category_id= $_GET['cat_id'];
$productid       = $_GET['productid'];
$producturl      = "

$message .= '<tr><td valign="top" align="center"><p style="font-family:arial; font-size:18px;color:#717783;"><a href="'.$producturl.'"><img src="/product-images/thumb/'.$thumb.'"  border="0" /></a><br><a style="color: #696969;font-family:arial; font-size:18px;" href="'.$producturl.'">Click Here</a> to view product details</p><div style="width:450px; font-family:arial; font-size:18px;color:#717783;">'.$productname.'</div><div style="width:450px; font-family:arial; font-size:18px;color:#717783;">'.$descriptions.'</div></td></tr></table>';}
$message .= '<p style="width:550px; font-family:arial; font-size:18px;color:#717783;">For more looks and options, please visit <a style="color: #696969;font-family:arial; font-size:18px;" href=".</p><br><p style="width:450px; font-family:arial; font-size:18px;color:#717783;"><br><br> Phone:(312) 733-9700</p>';
mail($email, $subject, $message, $headers);
Lukasz Chmielewski

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros