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
-
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
-
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 ‘)’
-
Can u guys please help me fix up mailing_list.php?
thanks for ur patience to read thru this and ANY HELP IS APPCRECIATED