Jump to content

code problems


ballhogjoni

Recommended Posts

For some reason my code is not working. I mean that when someone enters their info in the fields (not shown in code below) it stops at the first part:

 

if ($action == "sub") {

echo $emailPost;

 

It will not move on to any other part of the script. Can some one help me out. Thx.

 

<?php
if ($action == "sub") {
echo $emailPost;
if (empty($emailPost)) { 
	echo("Please enter an email address! <a href=\"index.php\">Go back</a>.<br />");
} else {
	$res = mysql_query("SELECT * FROM newsblitz_list WHERE email_addr = '".$emailPost."'") or die(mysql_error());
	$row = mysql_fetch_array($res) or die(mysql_error());
	if ($row['email_addr'] == $emailPost && $row['gets_mail'] == 1) {
      		echo("<strong>$emailPost</strong> is already subscribed to $news_name! <a href=\"index.php\">Go back</a>.<br />");
	} else {
    		if ($row['email_addr'] != $emailPost) {
			$date = Date('m/d/y h:ia');
			$query = "INSERT INTO newsblitz_list (fname,email_addr,date_subscribed,gets_mail) VALUES ('$name','$emailPost','$date','0')";
			$res = mysql_query($query) or die(mysql_error());
			$name = $_POST['name'];
			$confurl = "http://nnnnnn.com/mailer/index.php?action=conf&addr=$id,".md5($emailPost);
			$subject = "[$news_name] Newsletter Confirmation";
			$message = "$name,\n\nSomebody (hopefully you) has chosen to subscribe this email address to $news_name.\n\nIf you would like to receive our newsletter, then please confirm your subscription by going to the confirmation URL below. Otherwise, you can safely disregard this message.\n\nThanks,\n$admin_email\n\nConfirmation URL: $confurl\n";
			$from = $from_email;
			$headers = "From: $from";
			mail($emailPost,$subject,$message,$headers);
			echo("<strong>$emailPost</strong> has been subscribed to $news_name. Please check your inbox; you'll receive an email shortly to confirm your subscription. <a href=\"index.php\">Go back</a>.<br />");
      		} else {
			$id = $row['id'];
			$date = Date('m/d/y h:ia');
			$confurl = "http://nnnnnnnnnnn.com/mailer/index.php?action=conf&addr=$id,".md5($emailPost);
			$subject = "[$news_name] Newsletter Confirmation";
			$message = "$name,\n\nSomebody (hopefully you) has chosen to subscribe this email address to $news_name.\n\nIf you would like to receive our newsletter, then please confirm your subscription by going to the confirmation URL below. Otherwise, you can safely disregard this message.\n\nThanks,\n$admin_email\n\nConfirmation URL: $confurl\n";
			$from = $from_email;
			$headers = "From: $from";
			mail($from,$subject,$message,$headers);
			echo("<strong>$emailPost</strong> has been subscribed to $news_name. Please check your inbox; you'll receive an email shortly to confirm your subscription. <a href=\"index.php\">Go back</a>.<br />");
  		}
	}
}
}
?>

Link to comment
Share on other sites

Try this...this will tell you exactly what IF statement is giving you problems, post what you get.

 

<?php

if ($action == "sub") {
    echo $emailPost;
    
    if (empty($emailPost)) {
        echo("Please enter an email address! <a href=\"index.php\">Go back</a>.<br />");
    } else {
        $res = mysql_query("SELECT * FROM newsblitz_list WHERE email_addr = '".$emailPost."'") or die(mysql_error());
        $row = mysql_fetch_array($res) or die(mysql_error());
        
        if ($row['email_addr'] == $emailPost && $row['gets_mail'] == 1) {
            echo("<strong>$emailPost</strong> is already subscribed to $news_name! <a href=\"index.php\">
            Go back</a>.<br />");
        } else {
        
            if ($row['email_addr'] != $emailPost) {
                $date = Date('m/d/y h:ia');
                $query = "INSERT INTO newsblitz_list (fname,email_addr,date_subscribed,gets_mail) 
                VALUES ('$name','$emailPost','$date','0')";
                $res = mysql_query($query) or die(mysql_error());
                $name = $_POST['name'];
                $confurl = "http://nnnnnn.com/mailer/index.php?action=conf&addr=$id,".md5($emailPost);
                $subject = "[$news_name] Newsletter Confirmation";
                $message = "$name,\n\nSomebody (hopefully you) has chosen to subscribe this email address to 
                $news_name.\n\nIf you would like to receive our newsletter, then please confirm your subscription 
                by going to the confirmation URL below. Otherwise, you can safely disregard this message.
                \n\nThanks,\n$admin_email\n\nConfirmation URL: $confurl\n";
                $from = $from_email;
                $headers = "From: $from";
                mail($emailPost,$subject,$message,$headers);
                echo("<strong>$emailPost</strong> has been subscribed to $news_name. Please check your inbox; 
                you'll receive an email shortly to confirm your subscription. <a href=\"index.php\">Go back</a>.<br />");
            } else {
                $id = $row['id'];
                $date = Date('m/d/y h:ia');
                $confurl = "http://nnnnnnnnnnn.com/mailer/index.php?action=conf&addr=$id,".md5($emailPost);
                $subject = "[$news_name] Newsletter Confirmation";
                $message = "$name,\n\nSomebody (hopefully you) has chosen to subscribe this email address to 
                $news_name.\n\nIf you would like to receive our newsletter, then please confirm your subscription by 
                going to the confirmation URL below. Otherwise, you can safely disregard this message.
                \n\nThanks,\n$admin_email\n\nConfirmation URL: $confurl\n";
                $from = $from_email;
                $headers = "From: $from";
                mail($from,$subject,$message,$headers);
                echo("<strong>$emailPost</strong> has been subscribed to $news_name. Please check your inbox; 
                you'll receive an email shortly to confirm your subscription. <a href=\"index.php\">Go back</a>.<br />");
            } else {
               echo "I don't think you will get this one...";
            }
        } else {
           echo '($row[email_addr] == $emailPost && $row[gets_mail] == 1) not working right...';
         }
    } else {
      echo "I hope you dont' get this error...";
   }
} else {
   echo '$action == "sub" not set';
}

?>

Link to comment
Share on other sites

After this:

<?php

if ($action == "sub") {
    echo $emailPost;
    
    if (empty($emailPost)) {
        echo("Please enter an email address! <a href=\"index.php\">Go back</a>.<br />");
    } else {
?>

 

is the problem.

 

Problem code:

<?php
$res = mysql_query("SELECT * FROM newsblitz_list WHERE email_addr = '".$emailPost."'") or die(mysql_error());
	$row = mysql_fetch_array($res) or die(mysql_error());
	if ($row['email_addr'] == $emailPost && $row['gets_mail'] == 1) {
      		echo("<strong>$emailPost</strong> is already subscribed to $news_name! <a href=\"index.php\">Go back</a>.<br />");
	} else {
    		if ($row['email_addr'] != $emailPost) {
			$date = Date('m/d/y h:ia');
			$query = "INSERT INTO newsblitz_list (fname,email_addr,date_subscribed,gets_mail) VALUES ('$name','$emailPost','$date','0')";
			$res = mysql_query($query) or die(mysql_error());
			$name = $_POST['name'];
			$confurl = "http://nnnnnn.com/mailer/index.php?action=conf&addr=$id,".md5($emailPost);
			$subject = "[$news_name] Newsletter Confirmation";
			$message = "$name,\n\nSomebody (hopefully you) has chosen to subscribe this email address to $news_name.\n\nIf you would like to receive our newsletter, then please confirm your subscription by going to the confirmation URL below. Otherwise, you can safely disregard this message.\n\nThanks,\n$admin_email\n\nConfirmation URL: $confurl\n";
			$from = $from_email;
			$headers = "From: $from";
			mail($emailPost,$subject,$message,$headers);
			echo("<strong>$emailPost</strong> has been subscribed to $news_name. Please check your inbox; you'll receive an email shortly to confirm your subscription. <a href=\"index.php\">Go back</a>.<br />");
      		} else {
			$id = $row['id'];
			$date = Date('m/d/y h:ia');
			$confurl = "http://nnnnnnnnnnn.com/mailer/index.php?action=conf&addr=$id,".md5($emailPost);
			$subject = "[$news_name] Newsletter Confirmation";
			$message = "$name,\n\nSomebody (hopefully you) has chosen to subscribe this email address to $news_name.\n\nIf you would like to receive our newsletter, then please confirm your subscription by going to the confirmation URL below. Otherwise, you can safely disregard this message.\n\nThanks,\n$admin_email\n\nConfirmation URL: $confurl\n";
			$from = $from_email;
			$headers = "From: $from";
			mail($from,$subject,$message,$headers);
			echo("<strong>$emailPost</strong> has been subscribed to $news_name. Please check your inbox; you'll receive an email shortly to confirm your subscription. <a href=\"index.php\">Go back</a>.<br />");
  		}
	}
}
}
?>

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.