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
https://forums.phpfreaks.com/topic/77529-code-problems/
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
https://forums.phpfreaks.com/topic/77529-code-problems/#findComment-392466
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
https://forums.phpfreaks.com/topic/77529-code-problems/#findComment-392876
Share on other sites

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.