Mailing list--UPDATE?

so my project is to create a update mailing list to notify the users through email about the entries that they have been searching for, once such entries are updated.

Let me explain it bit by bit…

First John (for example) searches sthg on database and can’t find anything.

So John subscribes for the update mailing list as mentioned above. This mailing list has table (as in database) with a field “query”, of coz along with user’s email and name.

On the other hand, other users like Peter submits his entry into the database, and if such entry MATCHES the “query” in the mailing list that Peter requested, he would receive an email informing him like hay the stuff u looking for is in database now

So my idea is to connect the Add Entry script with the mailing list, so once the Peter put new entries John could receive notification right away

Below is my addEntry.php



<?php
//Database Credentials
include "../db_fns.php";


session_start();

//Database connection
$conn = db_connect_2();

if (isset($_SESSION['link']) AND !isset($_POST['Submit'])){
    //retrieve link
    if(is_string($_SESSION['link'])){
    $link = unserialize($_SESSION['link']);
    } else {
        $link = $_SESSION['link'];
    }
    if($link){
        //basic stuff
        $_SESSION['transgene_type'] = (string)$link->tt_id;
        $_SESSION['promoter_locus'] = $link->promoter; 
        $_SESSION['PromoLocusSynonyms'] = $link->pl_synonyms;
        $_SESSION['species'] = (string)$link->s_id;
        
        //genetic background
        //clear it just incase there are values since another time
        $_SESSION['genetic_bg'] = array();
        $_SESSION['GeneticBGOtherTxt'] = "";
        foreach($link->genetic_bg as $gbg){
            //we check if it is a menu selected item or an item that is not in menu
            if((int)$gbg['GBG_IS_MENU']){
                $_SESSION['genetic_bg'][] = $gbg['GBG_ID'];
            } else {
                //belongs in other
                if(empty($_SESSION['GeneticBGOtherTxt'])) {
                    $_SESSION['GeneticBGOtherTxt'] .= $gbg['GBG_NAME'];
                } else { 
                    $_SESSION['GeneticBGOtherTxt'] .= ",".$gbg['GBG_NAME'];
                }
            } 
        }    
    $_POST = $_SESSION;                  
}elseif (isset($_POST['Submit'])) {

       if(isset($_SESSION['link'])) {
            //we need to unserialize the link    
            if(is_string($_SESSION['link'])){
            $link = unserialize($_SESSION['link']);  //unserialize() takes a single variable and converts it back into a php value
            } else {
                $link = $_SESSION['link'];
            }              
        }

        //put $_POST variables into $_SESSION
        $_SESSION = $_POST + $_SESSION;
        unset($_SESSION['Submit']);

	

	

// CHECK FOR ERRORS AFTER SUBMISSION

	

	

$errors = array(); // Set array

	

	

if (!$_POST['promoter_locus'])

	

	

	

$errors[] = "Please specify a value for \\"Promoter or Locus\\"".$PromoLocus;

	

	

if (!$_POST['transgene_type'])

	

	

	

$errors[] = "Please specify a value for \\"Transgene Type\\"";

	

	

if (!$_POST['inducible_systems'] && !$_POST['InducibleSystemsOther'])

	

	

	

$errors[] = "Please specify an \\"Inducibility\\" value";

	

	

}

	

	

if (count($errors) > 0 ) {

	

	

	

$iferrors = "Yes";

	

	

} else {

	

	

	


    [B][U]include ('mailing_list.php');
           checkPromoter($_POST['promoter_locus'];[/U][/B]

                //this is to check that step one has been completed once we go to step 2
                 $_SESSION['step'] = 2;
                 header("Location: StepTwo_2.php");
                 exit;    
            }

	

	

}

}
else {
    session_trash_();
    session_regenerate_id(true);
}



Note that this script is an excerpt and I make the lines that I put to be bold and underlined.

This is the mailing_list.php



<?php

require('connection.php');

function checkPromoter ($_POST['promoter_locus']) {

	

$check = "select id from mailing_list where query = '$_POST['promoter_locus']'";

	

$result = mysqli_query($connect, $check) or die(mysqli_error($connect));

	




	

if (mysqli_num_rows($result)==0){

	

	

continue;

	

} else {

	


	

$sql = "select email from mailing_list where query = '$_POST['promoter_locus']'";

	


	

$query = $_POST['promoter_locus'];

	


	

$email = mysqli_query($connect, $sql) or die(mysqli_erro($connect));

	


	

$to = $email;

	

$subject = "The query is updated";

	

$headers = "From: asdfasdf";

	

$body = "

	

Hello

	

This is to inform you that $query is updated, please go to this link to search for it:

	


	

http://asdfasdf

	

Regards,

	

asdfasdf.";

	

mail($to, $subject, $body, $headers);

	

die();

	

}

}



So my questions are

  1. Where should I place those bold lines in addEntry.php? I tried to run it but the result is a blank page… Also there’s no email sending through to my test email

  2. For the line function checkPromoter ($_POST[‘promoter_locus’]), should I put variable like $promoter = $_POST[‘promoter_locus’] ? Cuz I ran that and the error is Parse error: syntax error, unexpected ‘[’, expecting ‘)’

  3. Can u guys please help me fix up mailing_list.php?

thanks for ur patience to read thru this and ANY HELP IS APPCRECIATED :stuck_out_tongue:

Hey, Tommy. This one is a little beyond me. I hope someone with a little more knowledge can wrap this one. I will poke around and see what I can come up with.
Kevin

I don’t know if this is a copy paste error but:


<?php

   [B][U]include ('mailing_list.php');

           checkPromoter($_POST['promoter_locus'];[/U][/B]



                //this is to check that step one has been completed once we go to step 2

                 $_SESSION['step'] = 2;

                 header("Location: StepTwo_2.php");

                 exit;    

            }
            
?>

should be changed to:


<?php

   include ('mailing_list.php');

           checkPromoter($_POST['promoter_locus']); // I added the ending ")"



                //this is to check that step one has been completed once we go to step 2

                 $_SESSION['step'] = 2;

                 header("Location: StepTwo_2.php");

                 exit;    

            }
            
?>

Checking rest
Kevin

Thx for the quick reply

I have changed the mailing_list.php as follows:



<?php

include('connection.php');
$pro = $_POST['promoter_locus'];
function checkPromoter($pro){


$check = "select id from mailing_list where query = $pro";

$result = mysqli_query($connect, $check) or die(mysqli_error($connect);


if (mysqli_num_rows($result)==0){
continue;
} else {

$sql = "select email from mailing_list where query = '$pro'";

$email = mysqli_query($connect, $sql) or die(mysqli_error($connect));

$to = $email;
$subject = "The query is updated";
$headers = "From: Cre-X-Mice Database Administrator";
$body = "

Hello

This is to inform you that $pro is updated, please go to this link to search for it:

http://nagy.mshri.on.ca/Coop_Student/cre/search/Search_Coop_try3.php

Regards,

Cre-X-Mice Administrator.";
mail($to, $subject, $body, $headers);

die();

}

} 


Apparently there aren’t any errors or warnings showed up when I ran addEntry.php (which includes mailing_list.php), but when I submit the query it goes blank

So am i placing the checkPromoter( ) correctly in the addEntry.php??

And also the email didn’t send through… Plz help me fix it up :slight_smile:

Tommy,
Change this:


$check = "select id from mailing_list where query = $pro";

to:


$check = "select id from mailing_list where query = '$pro'";

Checking rest.

Try this to see if it’s mailed:


  $to = $email;
 $subject = "The query is updated";
 $body = "Hello\\r\
This is to inform you that $pro is updated, please go to this link to search for it:\\r\
 http://nagy.mshri.on.ca/Coop_Student/cre/search/Search_Coop_try3.php\\r\
 Regards,\\r\
 Cre-X-Mice Administrator.";

 $headers = "From: Cre-X-Mice Administrator <yourname@email.com>" .
     "X-Mailer: php";
 if (mail($to, $subject, $body, $headers)) {
   echo("<p>Message sent!</p>");
  } else {
   echo("<p>Message delivery failed...</p>");
  }


Thanks,
Kevin

You can also echo the email to see if it works with this:


 if (mail($to, $subject, $body, $headers)) {
   echo("<p>Message sent to $email !</p>");
  } else {
   echo("<p>Message delivery failed, Not sent to $email </p>");
  }  

I forgot some stuff in the previous post:

This should work:



$from_email = "you@yourdomain.com";
$to = $email;
$subject = "The query is updated";
$body = "Hello\\r\
\
This is to inform you that $pro is updated, please go to this link to search for it:\\r\
\
 http://nagy.mshri.on.ca/Coop_Student/cre/search/Search_Coop_try3.php\\r\
\
 Regards,\\r\
\
 Cre-X-Mice Administrator.";
$headers = "From: Cre-X-Mice Administrator <$from_email>\\r\
" . "X-Mailer: php";
if (mail($to, $subject, $body, $headers)) {
    echo("<p>Message sent to $email !</p>");
    } else {
    echo("<p>Message delivery failed sending to $email </p>");
}


hay buddy

i have changed mailing_list.php and inserted echo and while loop into it, still the blank page shows up after i submit the query

So i assume there’s problem with the positioning of the function (from mailing_list.php) in addEntry.php

just so u have more details, here’s the whole addEntry.php script:



<?php
//Database Credentials
include "../db_fns.php";

//Menu Functions
include "../menu_fns.php";

//User Functions
include "../user_fns.php";
include "../comment_fns.php";
//link fns
include "../links_fns_2.php";
include "../specificities_fns_2.php";
// Make Session / Session Variables.


session_start();

//Database connection
$conn = db_connect_2();
/*
    We retrieve information based on session ID, this is used if
    the person is redoing this step or if administrator is modifying
    the link. ALL MODIFICATIONS OF A LINK AND ITS SPECIFICITIES ARE 
    BASED ON $_SESSION['sid'] and $_SESSION['modify'].
*/
if (isset($_SESSION['link']) AND !isset($_POST['Submit'])){
    //retrieve link
    if(is_string($_SESSION['link'])){
    $link = unserialize($_SESSION['link']);
    } else {
        $link = $_SESSION['link'];
    }
    if($link){
        //basic stuff
        $_SESSION['transgene_type'] = (string)$link->tt_id;
        $_SESSION['promoter_locus'] = $link->promoter; 
        $_SESSION['PromoLocusSynonyms'] = $link->pl_synonyms;
        $_SESSION['species'] = (string)$link->s_id;
        $_SESSION['TransgeneInsertion'] = $link->transgene_insertion;
        $_SESSION['Published'] = $link->published;
        $_SESSION['pub_med_id'] = $link->pubmed_id;
        $_SESSION['author'] = $link->user_name;
        $_SESSION['email'] = $link->user_email;
        $_SESSION['mgi_id'] = $link->mgi_id;
        $_SESSION['HoldingStockNumber'] = $link->stock_num;
        
        //multiple
        
        //genetic background
        //clear it just incase there are values since another time
        $_SESSION['genetic_bg'] = array();
        $_SESSION['GeneticBGOtherTxt'] = "";
        foreach($link->genetic_bg as $gbg){
            //we check if it is a menu selected item or an item that is not in menu
            if((int)$gbg['GBG_IS_MENU']){
                $_SESSION['genetic_bg'][] = $gbg['GBG_ID'];
            } else {
                //belongs in other
                if(empty($_SESSION['GeneticBGOtherTxt'])) {
                    $_SESSION['GeneticBGOtherTxt'] .= $gbg['GBG_NAME'];
                } else { 
                    $_SESSION['GeneticBGOtherTxt'] .= ",".$gbg['GBG_NAME'];
                }
            } 
        }    
        
        //inducible systems
        //clear it just incase there are values since another time
        $_SESSION['inducible_systems'] = array();
        $_SESSION['InducibleSystemsOtherTxt'] = "";
        foreach($link->inducible_systems as $is){
            //we check if it is a menu selected item or an item that is not in menu
            if((int)$is['IS_IS_MENU']){
                $_SESSION['inducible_systems'][] = $is['IS_ID'];
            } else {
                //belongs in other
                if(empty($_SESSION['InducibleSystemsOtherTxt'])) {
                    $_SESSION['InducibleSystemsOtherTxt'] .= $is['IS_NAME'];
                } else { 
                    $_SESSION['InducibleSystemsOtherTxt'] .= ",".$is['IS_NAME'];
                }
            } 
        }
        
    
    $_POST = $_SESSION;                  
}elseif (isset($_POST['Submit'])) {

       if(isset($_SESSION['link'])) {
            //we need to unserialize the link    
            if(is_string($_SESSION['link'])){
            $link = unserialize($_SESSION['link']);  //unserialize() takes a single variable and converts it back into a php value
            } else {
                $link = $_SESSION['link'];
            }              
        }

        //put $_POST variables into $_SESSION
        $_SESSION = $_POST + $_SESSION;
        unset($_SESSION['Submit']);
		// CHECK FOR ERRORS AFTER SUBMISSION
		$errors = array(); // Set array

		// test to see if the form was actually
		// posted from our form... security
		$page = $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

		// Now Do The Checking.
		if (!ereg($page, $_SERVER['HTTP_REFERER']))
			$errors[] = "Invalid Referer - Please Report This Error To The Webmaster";
		if (!$_POST['promoter_locus'])
			$errors[] = "Please specify a value for \\"Promoter or Locus\\"".$PromoLocus;

		if (!$_POST['transgene_type'])
			$errors[] = "Please specify a value for \\"Transgene Type\\"";
		if (!$_POST['inducible_systems'] && !$_POST['InducibleSystemsOther'])
			$errors[] = "Please specify an \\"Inducibility\\" value";

		if (isset($_POST['inducible_systems'])) {
			if (in_array('52', $_POST['inducible_systems']) && (count($_POST['inducible_systems']) > 1 || !empty($_POST['InducibleSystemsOther']))) {
				$errors[] = "\\"Inducibility\\" values contradict";
			}
		}
		//if (empty($_POST['Holding']) && empty($_POST['HoldingOthers']))
		//	$errors[] = "Please specify a holding site";
		if (!isset($_POST['Published']))
			$errors[] = "Please specify whether this entry is Published";
        $published = (int)$_POST['Published'];
		if (!$_POST['species'] OR ($_POST['species'] == 'Other' AND empty($_POST['SpeciesOtherTxt'])))
			$errors[] = "Please specify a \\"Promoter Species\\" for this entry";
		if ($published AND empty($_POST['pub_med_id']))
			$errors[] = "Please provide a value for \\"PubMed ID\\"";
		if ($published AND empty($_POST['author']))
			$errors[] = "Please specify the Author of the publication";
		if ($published AND empty($_POST['email']))
			$errors[] = "Please provide an email address for the Author";
		if ($published AND !valid_email($_POST['email']))
			$errors[] = "Please Provide A VALID Email Address for the Author";
		if ($published AND !empty($_POST['pub_med_id']) AND !is_numeric($_POST['pub_med_id']))
			$errors[] = "PubMed ID Must Be Numeric";
		if (!empty($_POST['mgi_id']) && !is_numeric($_POST['mgi_id']))
			$errors[] = "MGI ID Must Be Numeric";
		if (!$_POST['genetic_bg'] OR($_POST['genetic_bg'][0] == 'Other' 
        AND sizeof($_POST['genetic_bg'] == 1)
        AND empty($_POST['GeneticBGOtherTxt'])))
			$errors[] = "Please specify a \\"Genetic Background\\"";


		// Count Errors For Errors	// Set variable for printing errors below in <body>
		if (count($errors) > 0 ) {
			$iferrors = "Yes";

		} else {
                //this is to check that step one has been completed once we go to step 2
                 $_SESSION['step'] = 2;
                 header("Location: StepTwo_2.php");
                 exit;    
            }
            

			
			
		
			
		}

}
else {
    session_trash_();
    session_regenerate_id(true);
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="../css/css.css" rel="stylesheet" type="text/css" />
<link href="../suggestive_search/suggestive_search.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title><?php echo $appName;?> | Add: Step One</title>
<script language="JavaScript" src="../javaScript/javascript.js" type="text/javascript"></script>
<script src="../javaScript/jquery.js"></script>
<script language="JavaScript" src="../javaScript/java_functions.js" type="text/javascript"></script>
<script language="JavaScript" src="../suggestive_search/suggestive_search.js" type="text/javascript"></script>  

<script language="javascript">
function enablePublishedLink() {
	document.Start.PublishedLink.disabled=false;
}
function disablePublishedLink() {
	document.Start.PublishedLink.disabled=true;
}

function showPublishedInfo() {
	$("#published").slideDown("slow");
}

function hidePublishedInfo() {
	$("#published").slideUp("slow");
}

</script>
</head>
<body>
<!-- Main Table -->
<table width="100%" border="0" cellpadding="0" cellspacing="0" id="outerTable">
<!-- Header -->
<tr>
   <td height="10" valign="top"> <?php include "../header.php"; ?> </td>
</tr>
<!-- Body Content -->
  <tr>
    <td valign="top">
		<table width="100%" border="0" cellpadding="0" cellspacing="0" id="innerTable">
		  <tr>
			<td width="180" valign="top" class="sideBarBG"><div align="center"><?php include "../sidebar.php"; ?></div></td>
			<td valign="top" id="bodyContent"><div class="pageTitle">Submit Cre Transgenic Line - Step 1 of 3</div>
		    <p class="sectionTitle">Please complete the following information.</p>
			  <p>
			    <?php
				if ($iferrors == "Yes"){
					echo "<div class=\\"errorText\\">";
					foreach($errors as $err) {
						echo "$err <br />\
";
					}
					echo "</div>";
				}
			?>
			  </p>
			  <form name="Start"  method="post" action="<?php echo $_SERVER['PHP_SELF'].'?';?>">

			    <p><span class="formLabelsS2">Transgene Type</span></p>
			    <p class="S2Form">
				<label>
			    <input type="radio" name="transgene_type" value="1" <?php if ($_SESSION['transgene_type'] == "1") { echo " Checked=\\"checked\\" "; } ?> />
			    Knock-In</label>
                <br />
                <label>
                <input type="radio" name="transgene_type" value="2" <?php if ($_SESSION['transgene_type'] == "2") { echo " Checked=\\"checked\\" "; } ?> />
                Genetrap</label>
                <br />
                <label>
                <input type="radio" name="transgene_type" value="3" <?php if ($_SESSION['transgene_type'] == "3") { echo " Checked=\\"checked\\" "; } ?> />
                Random Insertion</label>
				</p>
                <p><span class="formLabelsS2">Promoter or Locus</span> </p>
                <p class="S2Form">
                  <input name="promoter_locus" type="text" class="basicTextField" id="promoter_locus"
                   value="<?php echo $_SESSION['promoter_locus']; ?>"
                   onkeyup="suggest_search('promoter_locus','promo_locus_suggest',$(this).val()+'%',$(this).attr('id'));"
                   maxlength="255" />
                  <div id="promo_locus_suggest" class="suggestive_main_div" ></div>
                </p>
                                             
                <p class="S2Form" >Specify synonyms of "Promoter and Locus" below.<br />
					Seperate multiple entries with a comma. <br />
                  <input name="PromoLocusSynonyms" type="text" class="basicTextField" id="PromoLocusSynonyms" value="<?php echo $_SESSION['PromoLocusSynonyms']; ?>" maxlength="255" />
                </p>
                <p><span class="formLabelsS2">Promoter Species</span>                </p>
                <p class="S2Form">
                  <select name="species" class="basicMenu" id="species" 
                  onChange="toggleOther('species','SpeciesOther','SpeciesOtherTxt')">
                   				<option value="">Choose from List</option>
                    			<?php
									menu_display("species");
								?>
                  				</select>
                </p>
                <p id="SpeciesOther"
                <?php menu_display_other("species");?>>
                Specify unlisted species below.<br />
				<input name="SpeciesOtherTxt" type="text" class="basicTextField" id="SpeciesOtherTxt" value="<?php echo $_SESSION['SpeciesOtherTxt']; ?>" maxlength="255" />
                </p>
                <p><span class="formLabelsS2">Transgene Insertion</span> </p>
                <p class="S2Form">
                  <input name="TransgeneInsertion" type="text" class="basicTextField" id="TransgeneInsertion" value="<?php echo $_SESSION['TransgeneInsertion']; ?>" maxlength="255" />
                </p>
                <p><span class="formLabelsS2">Inducibility</span></p>
                <p class="S2Form">
                  <select name="inducible_systems[]" size="5" multiple="multiple" class="basicMenu" id="InducibleSystems"
                  onChange="toggleOther('InducibleSystems','InducibleSystemsOther','InducibleSystemsOtherTxt')">
                    <?php
						menu_display("inducible_systems")
					?>
                  </select>
                </p>
                <p class="S2Form" id="InducibleSystemsOther"
                <?php menu_display_other("inducible_systems");?>>
                		Specify unlisted inducible systems below.<br />
						Seperate multiple entries with a comma. <br />
                  <input name="InducibleSystemsOtherTxt" type="text" class="basicTextField" id="InducibleSystemsOtherTxt" value="<?php echo $_SESSION['InducibleSystemsOtherTxt']; ?>" maxlength="255" />
                </p>
                <p><span class="formLabelsS2">Genetic Background</span>                </p>
                <p class="S2Form">
                  <select name="genetic_bg[]" size="5" multiple="multiple" class="basicMenu" id="genetic_bg"
                  onChange="toggleOther('genetic_bg','GeneticBGOther','GeneticBGOtherTxt')">
                    <?php
						menu_display("genetic_bg");
					?>
                  </select>
				</p>
				<p class="S2Form" id="GeneticBGOther"
				<?php menu_display_other("genetic_bg");
    			?>>
					Specify unlisted Genetic Backgrounds below.<br />
					Seperate multiple entries with a comma. <br />
					<input name="GeneticBGOtherTxt" type="text" class="basicTextField" id="GeneticBGOtherTxt" value="<?php echo $_SESSION['GeneticBGOtherTxt']; ?>" maxlength="255" />
                </p>
                <p><span class="formLabelsS2">Is this Cre Transgenic Line Published?</span></p>
                <p class="S2Form">
                  <label><input type="radio" name="Published" value="0" onclick="javascript:hidePublishedInfo()" <?php if ($_SESSION['Published'] == "0") { echo " Checked=\\"checked\\" "; } ?> />No</label>
                  <label><input type="radio" name="Published" value="1" onclick="javascript:showPublishedInfo()" <?php if ($_SESSION['Published'] == "1") { echo " Checked=\\"checked\\" "; } ?> />Yes</label>
                </p>
                  <div <?php if ($_SESSION['Published'] != 1){ echo "style=\\"display:none\\""; } ?> id="published">
                		PubMed ID<br />
                		<input name="pub_med_id" type="text" class="basicTextField" id="pub_med_id" value="<?php echo $_SESSION['pub_med_id']; ?>" /><br />
                		Author's name<br />
			  			<input name="author" type="text" class="basicTextField" id="author"
                        <?
                            //if author is logged in we put his name and dont allow him to edit it
                            if(isset($_SESSION['user_id']) AND !isset($_SESSION['author']) AND !isset($_SESSION['author'])){
                                echo " value=\\"{$_SESSION['user_name']}\\" ";
                            } else {
                                echo " value=\\"{$_SESSION['author']}\\" ";
                            }
                        ?> /><br />
			  			Author's Email Address<br />
			  			<input name="email" type="text" class="basicTextField" id="email"                         
                        <?
                            //if author is logged in we put his name and dont allow him to edit it
                            if(isset($_SESSION['user_id']) AND !isset($_POST['email']) AND !isset($_SESSION['email'])){
                                echo " value=\\"{$_SESSION['user_email']}\\"";
                            } else {
                                echo " value=\\"{$_SESSION['email']}\\" ";
                            }
                        ?>  />
             		</div>
              <p><span class="formLabelsS2">MGI ID </span>(Optional)</p>
                <p class="S2Form">
                  <input name="mgi_id" type="text" class="basicTextField" id="mgi_id" value="<?php echo $_SESSION['mgi_id']; ?>" maxlength="255" />
                </p>
			  <p><span class="formLabelsS2">Holding Sites </span>(Optional)</p>
			  <p class="S2Form">
                <select name="holding_sites[]" size="5" multiple="multiple" class="basicMenu" id="holding_sites"
                onChange="toggleOther('holding_sites','HoldingOther','HoldingOtherTxt')">
                  <?php
						menu_display("holding_sites");
					?>
                </select>
              </p>
			  <p class="S2Form" id="HoldingOther" <?php menu_display_other("holding_sites");?>>
			  	Specify unlisted Holding Sites below.<br />
			    Seperate multiple entries with a comma. <br />
                  <input name="HoldingOtherTxt" type="text" class="basicTextField" id="HoldingOtherTxt" value="<?php 
                  echo $_SESSION['HoldingOtherTxt']; 
                  ?>" />
              </p>
              <p class="S2Form">Holding Site Stock# or URL (Optional)<br />
                  <input name="HoldingStockNumber" type="text" class="basicTextField" id="HoldingStockNumber" value="<?php echo $_SESSION['HoldingStockNumber']; ?>" />
              </p>
                <p>&nbsp;                </p>
                <p>
                  <input name="Submit" type="submit" id="Submit" value="Continue" />
                </p>
			  </form>		    </td>
		  </tr>
		</table>
	</td>
  </tr>
</table>
</body>
</html>


ya ya i no it’s a huge ass script, but i think i just need to find the RIGHT POSITIONING to place the function so it can all work out

I am thinking of putting the mailing_list.php function right before the <html> starts, as it is the ending point of the php script where all the data submitted by users are saved and it’s ready to proceed to step 2.

Not very sure tho.

THX FOR THE HELP!! :smiley:

Hey, bud.

Try putting session_start() before all code right at the top after the first <?php before the includes.

Looking it over now.

Quick update:

so i decide to simply insert mailing_list.php directly like this:



if($_SESSION['step'] == 3){
//this means we already did step two and
//clicked edit step one on last page
header("Location: StepThree_2.php");
exit;
} else {

if($_POST['promoter_locus']){
include "mailing_list.php";}
//this is to check that step one has been completed once we go to step 2
$_SESSION['step'] = 2;
header("Location: StepTwo_2.php");
exit;
}





}

}
else {
session_trash_();
session_regenerate_id(true);
}


Note that this is toward the very end of the php section of addEntry.php above.

Now it’s like the page is ignoring its existence. Basically the page still goes normally from step 1 to step 2, but no email was sent whatsoever. Also no echo results are found. So i think it just skips mailing_list.php.

Again the main question is… what should I put mailing_list.php?

edit this but see if this is what you want:


if($_SESSION['step'] == 3){
//this means we already did step two and
//clicked edit step one on last page
header("Location: StepThree_2.php");
exit;
} elseif ($_POST['promoter_locus']) {
include "mailing_list.php";
// I think we should put an exit() after here
exit;
} else {
// $_SESSION['step'] == 2;
//this is to check that step one has been completed once we go to step 2
header("Location: StepTwo_2.php");
exit;
}

I think this would be better:


if($_SESSION['step'] == 3) {
//this means we already did step two and
//clicked edit step one on last page
header("Location: StepThree_2.php");
exit;
} elseif ($_SESSION['step'] == 2) {
//this is to check that step one has been completed once we go to step 2
header("Location: StepTwo_2.php");
exit;
} else {
include "mailing_list.php";
// I think we should put an exit() after here
exit;
}

Let me know. I may have to set up a fake table and see on my production site to get it working if this doesn’t work. Let me know

Thanks,bud.
Kevin

I dun think it’s a good idea to exit after include(‘mailing_list.php’) because step 2 is required after step 1…

I think there’s sthg that’s not efficient with the SQL in mailing_list.php and that prevents it from doing its job.

I will keep experimenting on the script and ur feedback is appreciated ! :cool:

It’s really a good idea about further expressions.

hay kevin

so i made further changes to mailing_list.php

please take a look and gimme some feedback




<?php

global $connect;
$connect = mysqli_connect("localhost", "asdfasdf", "asdfadf") or die(mysqli_error($connect));
$error = mysqli_error($connect);
$db_select = mysqli_select_db($connect, wefdewfdswe");

$pro = $_POST['promoter_locus'];

$check = "select mailing_list.id from mailing_list INNER JOIN promoter_locus on promoter_locus.PL_NAME = mailing_list.query";

$result = mysqli_query($connect, $check) or die(mysqli_error($connect));


if (mysqli_num_rows($result)==0){
continue;


} else {

while ($row = mysqli_fetch_array($result)){

extract($row);

$id = $row['id'];
}

$sql = "select email from mailing_list where id = '$id'";

$query = $_POST['promoter_locus'];

$result2 = mysqli_query($connect, $sql) or die(mysqli_error($connect));

while ($row2 = mysqli_fetch_array($result2)){

extract($row2);

$email = $row2['email'];
}


$to = $email;
$subject = "The query is updated";
$headers = "From: Cre-X-Mice Database Administrator"."X-Mailer: php";
$body = "

Hello

This is to inform you that $pro is updated, please go to this link to search for it:

http://nagy.mshri.on.ca/Coop_Student/cre/search/Search_Coop_try3.php

Regards,

Cre-X-Mice Administrator.";
if (mail($to, $subject, $body, $headers)){

echo("<p>Message sent!</p>");
} else {echo("<p>Message delivery failed</p>");}



}

?>

I place the mailing_list.php at the position i mentioned above, because i want both Step2 script as well as mailing_list.php to go thru once the entry is submitted

however the following error comes up:

Message delivery failed

Warning: Cannot modify header information - headers already sent by (output started at /mnt/r0120/d33/s26/b02e3c4b/www/nagy.mshri.on.ca/Coop_Student/cre/addEntry/mailing_list.php:59) in /mnt/r0120/d33/s26/b02e3c4b/www/nagy.mshri.on.ca/Coop_Student/cre/addEntry/StepOne_3.php on line 304

which points to this:



if($_SESSION['step'] == 3){
//this means we already did step two and
//clicked edit step one on last page
header("Location: StepThree_2.php");
exit;
} else {

include('mailing_list.php');
//this is to check that step one has been completed once we go to step 2
$_SESSION['step'] = 2;
header("Location: StepTwo_2.php");
exit;
}


so my questions are:

  1. What’s wrong with the header

  2. Apparently there aren’t any major mistakes in SQL part of mailing_list.php but somehow it echoes out Message delivery failed (well at least it’s echoing sthg out lol i think we r getting there…)

Once again, I really appreciate your passion in php and helping noobs like me lol :rofl:

I am so sorry, it’s because of the echo if else where the message sent or fails. It outputs en echo before the header of step2. LOL

Remove this:
[COLOR=#000000][COLOR=#dd0000]if (mail($to, $subject, $body, $headers)){

echo("[/COLOR]<p>Message sent!</p>“);
} else {echo(”
<p>Message delivery failed</p>");
[/COLOR]
and just use the header mail. Also for the body of the email, try to use

instead of the returns.

like this:



$from_email = "you@yourdomain.com";

$to = $email;

$subject = "The query is updated";

$body = "Hello\\r\
\
This is to inform you that $pro is updated, please go to this link to search for it:\\r\
\
 http://nagy.mshri.on.ca/Coop_Student/cre/search/Search_Coop_try3.php\\r\
\
 Regards,\\r\
\
 Cre-X-Mice Administrator.";

$headers = "From: Cre-X-Mice Administrator <$from_email>\\r\
" . "X-Mailer: php";

mail($to, $subject, $body, $headers);


The \r

will add carriage returns automatically. I did test this on my server using my email address as the to and from and it does work awesome. I think it may be failing because of the carriage returns in the body message. You can create a php page with just the mail prog. like this:


<?php

$email = "your-to-email@yourdomain.com";
$from_email = "you@yourdomain.com";
$to = $email;
$subject = "The query is updated";
$body = "Hello\\r\
\
This is to inform you that $pro is updated, please go to this link to search for it:\\r\
\
 http://nagy.mshri.on.ca/Coop_Student/cre/search/Search_Coop_try3.php\\r\
\
 Regards,\\r\
\
 Cre-X-Mice Administrator.";
$headers = "From: Cre-X-Mice Administrator <$from_email>\\r\
" . "X-Mailer: php";
if (mail($to, $subject, $body, $headers)) {
    echo("<p>Message sent to $email !</p>");
    } else {
    echo("<p>Message delivery failed sending to $email </p>");
}
?>

Then you can see that it works, then use your body and you will notice it fails.

Thanks,
Kevin

k i removed echo function and now no errors pop up

but still i guess it ignores mailing_list.php once again and just go directly to step2

y do i say this? because i use the following test:

so i believe u remember the mailing list u helped me to make, as u can check it out right here:

http://nagy.mshri.on.ca/Coop_Student/cre/search/Search_Coop_try3.php

i purposely enter a query in mailing list (at the bottom) to be, say, “hello” and also use my email to subscribe

then i submit an entry “hello”, which is on this page:

http://nagy.mshri.on.ca/Coop_Student/cre/addEntry/StepOne_3.php

this is basically the addEntry.php
next i click Continue to proceed to step 2

Finally i check my email, nothing has been sent

So kevin

i know this is a BIGGGGG favour that may take u some time

but could u plz make a simple mailing list page (like the one u taught me to make) as well as a simple entry submit page (like addEntry.php)

and try to include my mailing_list.php into ur entry submit page script to see if this update notification email function really works?

again, i no this may be too much to ask for, or u can just point out the mistakes in the mailing_list.php i just posted directly, or any other methods u think would be solutions in this case… plz plz plz let me know

Thx and respect, buddy

Tommy, No problem. I can set up my server to use a temp table and forms like yours.

I can’t use the mysqli though, just mysql_ :confused:

Also, give me some info on what some of the info should be in the text inputs.

I will pm you my email address and you can send me info on your tables structure and the php pages and stuff and I will work on it tonight and maybe tomorrow or next day have it working.

Thanks,
Kevin

Tommy,
pm sent. I will email you back with the working files.
Email me a zip file of your files, but leave out the db name, user and pass ok?
I will make a include connect.php and serve it that way.
Cool beans,
Kevin