tommy168 Posted February 14, 2011 Share Posted February 14, 2011 <?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 { [size="4"][b][u] include ('mailing_list.php'); checkPromoter($_POST['promoter_locus'];[/u][/b][/size] //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 plz help me fix up mailing_list.php? Thx for ur patience to read thru this and ANY HELP IS APPCRECIATED Quote Link to comment https://forums.phpfreaks.com/topic/227675-mailing-list-update/ Share on other sites More sharing options...
tommy168 Posted February 15, 2011 Author Share Posted February 15, 2011 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 Plz help!! Quote Link to comment https://forums.phpfreaks.com/topic/227675-mailing-list-update/#findComment-1174322 Share on other sites More sharing options...
tommy168 Posted February 15, 2011 Author Share Posted February 15, 2011 Help plz????? Quote Link to comment https://forums.phpfreaks.com/topic/227675-mailing-list-update/#findComment-1174539 Share on other sites More sharing options...
tommy168 Posted February 16, 2011 Author Share Posted February 16, 2011 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/cr ... p_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>");} } ?> however when I run addEntry.php (which includes mailing_list.php) 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 PLZZZZZZ HELP :confused: :confused: Quote Link to comment https://forums.phpfreaks.com/topic/227675-mailing-list-update/#findComment-1175210 Share on other sites More sharing options...
BlueSkyIS Posted February 16, 2011 Share Posted February 16, 2011 1. header error means there was output before you called header(). output can be anything: HTML, open space, anything. You can't output anything to browser before header() 2. this is invalid and i would expect a fatal parse error: $db_select = mysqli_select_db($connect, wefdewfdswe"); Quote Link to comment https://forums.phpfreaks.com/topic/227675-mailing-list-update/#findComment-1175259 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.