coalduststar Posted January 7, 2008 Share Posted January 7, 2008 Hi I'm trying to write up a script from scratch which will check a database to verify the lifespan of a page and then if the expiry date has been reached and/or exceded, it will email the page owner to warn of an impending deletion. This is probably terrible, inefficient code and if there are any other suggestions- i'll defo listen to them! But for now I keep getting this message when I load the page: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /web/vhosts/arts/test/philotest.php on line 22 Line 22 is the last one beginning "mail($..." I think I'm on the right track but I'm starting to make a bit of a balls of it... <?php ### email variables ### $cur_date = date('Y-m-d'); $subject = "Page content expired?"; $text = "Please check the content of the following page- http://www.coalduststar.com/".$row_owner['page_name']." as the information/content may be expired. The date set for review of this page was ".$expdate.". Please contact the designer responsible for this page (".$row_owner['page_name']."<".$row_owner['page_author_email'].">) to ensure that this page is not removed from the server- Thank You."; ### Gets page name and stores it to variable ### $currentFile = $_SERVER["PHP_SELF"]; $parts = Explode('/', $currentFile); $page_name1 = $parts[count($parts) - 1]; ### Recordset filtered to page name ### mysql_select_db($database_ownership, $ownership); $query_owner = "SELECT * FROM arts_ownership_history Where page_name = '$page_name1'"; $owner = mysql_query($query_owner, $ownership) or die(mysql_error()); $row_owner = mysql_fetch_assoc($owner); $totalRows_owner = mysql_num_rows($owner); ### Mail function (if page is out of date?) ### if($row_owner['page_expdate'] >= strtotime($cur_date) && $row_owner['$emailyn'] > 0){ mail($row_owner['page_owner_email'], $subject, $text, "From: $row_owner['page_author'] <$row_owner['page_author_email']>"); } ?> thanks Quote Link to comment https://forums.phpfreaks.com/topic/84885-mailer/ Share on other sites More sharing options...
coalduststar Posted January 7, 2008 Author Share Posted January 7, 2008 ### Mail function (if page is out of date?) ### if($row_owner['page_expdate'] >= $cur_date && $row_owner['$emailyn'] > 0){ mail($row_owner['page_owner_email'], $subject, $text, "From: $row_owner['page_author'] <$row_owner['page_author_email']>"); } Update- changed "strtotime($cur_date)" to "$cur_date" cos it didn't match the "DATE" data type inthe database- still the same error but now it's on the final line of the mail function which is essentially just a "}" no ideas? :-\ Quote Link to comment https://forums.phpfreaks.com/topic/84885-mailer/#findComment-432758 Share on other sites More sharing options...
coalduststar Posted January 9, 2008 Author Share Posted January 9, 2008 Just to continue this monologue... - This no longer produces an error but it doesn't work either. What it's supposed to do is compare the current date to the date in the database and if the current date is equal to or excedes the stored date AND the value in the column page_emailyn is greater than "0", then I want the mailer to send an email to the page owner. Could someone point me in the direction of what i've done wrong- i think the insert a record stuff is wrong but I though the mailer would work at least ??? Please- i'm stumped! <?php require_once('../Connections/ownership.php'); ?> <?php ### current date ### $cur_date = date('Y-m-d'); ### Gets page name and stores it to variable ### $currentFile = $_SERVER["PHP_SELF"]; $parts = Explode('/', $currentFile); $page_name1 = $parts[count($parts) - 1]; ### Recordset filtered to page name ### mysql_select_db($database_ownership, $ownership); $query_owner = "SELECT * FROM arts_ownership_history Where page_name = '$page_name1'"; $owner = mysql_query($query_owner, $ownership) or die(mysql_error()); $row_owner = mysql_fetch_assoc($owner); $totalRows_owner = mysql_num_rows($owner); ### Mail function (if page is out of date?) ### $owner = $row_owner['page_owner_email']; $subject = "Page content expired?"; $text = "Please check the content of the following page- http://www.arts.ulster.ac.uk/".$row_owner['page_name']." as the information/content may be expired. The date set for review of this page was ".$row_owner['page_expdate'].". Please contact the designer responsible for this page (".$row_owner['page_author']."<".$row_owner['page_author_email'].">) to ensure that this page is not removed from the server- Thank You."; $author = $row_owner['page_author']; $email = $row_owner['page_author_email']; if($row_owner['page_expdate'] >= $cur_date && $row_owner['$page_emailyn'] > 0){ mail($owner,$subject,$text,"From: $author <$email>"); $row_owner['$emailyn'] = 1; $insertSQL = sprintf("INSERT INTO arts_ownership_history(page_emailyn) VALUES 1"); mysql_select_db($database_ownership, $ownership); $Result1 = mysql_query($insertSQL, $ownership) or die(mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84885-mailer/#findComment-434659 Share on other sites More sharing options...
The Little Guy Posted January 9, 2008 Share Posted January 9, 2008 mail($row_owner['page_owner_email'], $subject, $text, "From: {$row_owner['page_author']} <{$row_owner['page_author_email']}>"); Quote Link to comment https://forums.phpfreaks.com/topic/84885-mailer/#findComment-434660 Share on other sites More sharing options...
coalduststar Posted January 9, 2008 Author Share Posted January 9, 2008 Thanks- that looks a lot more efficient than what I had in before with all those variables but it didn't really change anything- there aren't any errors but the database isn't updating and the email isn't going out. thanks for taking a look! Quote Link to comment https://forums.phpfreaks.com/topic/84885-mailer/#findComment-434670 Share on other sites More sharing options...
coalduststar Posted January 10, 2008 Author Share Posted January 10, 2008 *bump Quote Link to comment https://forums.phpfreaks.com/topic/84885-mailer/#findComment-435445 Share on other sites More sharing options...
coalduststar Posted January 10, 2008 Author Share Posted January 10, 2008 Can no-one point me in the right direction? I think it might be the part where I'm updating the database? <?php require_once('../Connections/ownership.php'); ?> <?php ### current date ### $cur_date = date('Y-m-d'); ### Gets page name and stores it to variable ### $currentFile = $_SERVER["PHP_SELF"]; $parts = Explode('/', $currentFile); $page_name1 = $parts[count($parts) - 1]; ### Recordset filtered to page name ### mysql_select_db($database_ownership, $ownership); $query_owner = "SELECT * FROM arts_ownership_history Where page_name = '$page_name1'"; $owner = mysql_query($query_owner, $ownership) or die(mysql_error()); $row_owner = mysql_fetch_assoc($owner); $totalRows_owner = mysql_num_rows($owner); ### Mail function (if page is out of date?) ### $subject = "Page content expired?"; $text = "Please check the content of the following page- http://www.arts.ulster.ac.uk/".$row_owner['page_name']." as the information/content may be expired. The date set for review of this page was ".$row_owner['page_expdate'].". Please contact the designer responsible for this page (".$row_owner['page_author']."<".$row_owner['page_author_email'].">) to ensure that this page is not removed from the server- Thank You."; if($row_owner['page_expdate'] >= $cur_date && $row_owner['$page_emailyn'] > 0){ mail($row_owner['page_owner_email'], $subject, $text, "From: {$row_owner['page_author']} <{$row_owner['page_author_email']}>"); $row_owner['$emailyn'] = 1; $insertSQL = sprintf("INSERT INTO arts_ownership_history(page_emailyn) VALUES 1"); mysql_select_db($database_ownership, $ownership); $Result1 = mysql_query($insertSQL, $ownership) or die(mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84885-mailer/#findComment-435481 Share on other sites More sharing options...
adam291086 Posted January 10, 2008 Share Posted January 10, 2008 So whats not happening. Define the current problem Quote Link to comment https://forums.phpfreaks.com/topic/84885-mailer/#findComment-435483 Share on other sites More sharing options...
coalduststar Posted January 10, 2008 Author Share Posted January 10, 2008 Does the code look alright? It's not updating the database or sending out the email. I've set a record in the database with an expiry date before today's date. What's supposed to happen, if today's date is greater than the expiry date is that the mail() function should send and email out and also change a value in the page_emailyn column from 0 to 1 so that in the future, when this page is accessed, the email won't send everytime. Does that make any sense- it's to notify people to check the content of the pages to make sure it's up-to-date. Quote Link to comment https://forums.phpfreaks.com/topic/84885-mailer/#findComment-435537 Share on other sites More sharing options...
adam291086 Posted January 10, 2008 Share Posted January 10, 2008 How are you storing the expiry date in the database? Quote Link to comment https://forums.phpfreaks.com/topic/84885-mailer/#findComment-435546 Share on other sites More sharing options...
coalduststar Posted January 10, 2008 Author Share Posted January 10, 2008 erm? the data type is "date" in mySQL. Do i need to use strtotime or something? ah crap- is it that the $cur_date is a string? Like this : if(date($row_owner['page_expdate']) >= $cur_date && $row_owner['$page_emailyn'] > 0){ Quote Link to comment https://forums.phpfreaks.com/topic/84885-mailer/#findComment-435563 Share on other sites More sharing options...
coalduststar Posted January 10, 2008 Author Share Posted January 10, 2008 nope... :-\ still no errors but no action either and i've just realised what i've done is totally wrong- how would i get the date into the right format if it's in the wrong format to begin with? Changed to this: if(date($row_owner['page_expdate'], 'Y-m-d') >= $cur_date && $row_owner['$page_emailyn'] > 0){ and the error i get is: Warning: date() expects parameter 2 to be long, string given in /web/vhosts/arts/test/philotest.php on line 23 Quote Link to comment https://forums.phpfreaks.com/topic/84885-mailer/#findComment-435566 Share on other sites More sharing options...
adam291086 Posted January 10, 2008 Share Posted January 10, 2008 Ok i think this little script will search your database and echo any dates from the past. Lets get that working then we can start on the mail script. Make sure you change the date column name <?php require_once('../Connections/ownership.php') //current date $cur_date = date('Y-m-d'); // Recordset filtered to page name mysql_select_db($database_ownership, $ownership); $query_owner = "SELECT * FROM arts_ownership_history Where datecol < CURDATE() "; $owner = mysql_query($query_owner) or die(mysql_error()); while($row_owner = mysql_fetch_assoc($owner)) { echo $row_owner['datecol']; } //change datecol to the name of the column that stores the expiry date. ?> Quote Link to comment https://forums.phpfreaks.com/topic/84885-mailer/#findComment-435599 Share on other sites More sharing options...
coalduststar Posted January 10, 2008 Author Share Posted January 10, 2008 Ok that works 100% but i'm probably not explaining this correctly- i'm kind of trying to only pull the record that corresponds to this page. It's going to a database with the page names and expiry dates of the content. Then this code i'm busy butchering into nothing at the minute is going to be in the top of every php page so that whenever a user accesses the page the expiry date in the database that is checked against the current date and if the page has exceeded the date AND an email hasn't been sent previously (there's a boolean value in the database to record if an email has been sent) then the mail will send and the database will be told to change the boolean value to recrod that the email has been sent and to ensure that it isn't resent. But if this is part of fixing process then "hit me" cos it's driving me a bit mad! Quote Link to comment https://forums.phpfreaks.com/topic/84885-mailer/#findComment-435618 Share on other sites More sharing options...
adam291086 Posted January 10, 2008 Share Posted January 10, 2008 this is part of the process. LOL you can now search a database for passed dates. Therefore that will form the top part of every page. If this part of the code works [code] $currentFile = $_SERVER["PHP_SELF"]; $parts = Explode('/', $currentFile); $page_name1 = $parts[count($parts) - 1]; Then we can do this <?php require_once('../Connections/ownership.php') //current date $currentFile = $_SERVER["PHP_SELF"]; $parts = Explode('/', $currentFile); $page_name1 = $parts[count($parts) - 1]; // Recordset filtered to page name mysql_select_db($database_ownership, $ownership); $query_owner = "SELECT * FROM arts_ownership_history Where datecol < CURDATE() AND pagename = $page_name1 "; $owner = mysql_query($query_owner) or die(mysql_error()); while($row_owner = mysql_fetch_assoc($owner)) { echo $row_owner['datecol']; } //change datecol to the name of the column that stores the expiry date. ?> [/code] That will get everything from the database that has a certain page_name and the expiry date has passed. Tweek the code and get it to work. Quote Link to comment https://forums.phpfreaks.com/topic/84885-mailer/#findComment-435659 Share on other sites More sharing options...
coalduststar Posted January 10, 2008 Author Share Posted January 10, 2008 Thanks! Gonna give that a shot- have to head on here for a bit but I'll likely come crying back at some pont! You've been a great help! Quote Link to comment https://forums.phpfreaks.com/topic/84885-mailer/#findComment-435668 Share on other sites More sharing options...
adam291086 Posted January 10, 2008 Share Posted January 10, 2008 Just break it down into little bits. Once you have it working out expred dates you then need a simple mail script on its own. Get that working and then intergrate it into the script. Quote Link to comment https://forums.phpfreaks.com/topic/84885-mailer/#findComment-435671 Share on other sites More sharing options...
coalduststar Posted January 10, 2008 Author Share Posted January 10, 2008 yeah i think i was punching above my weight there! thanks man! Quote Link to comment https://forums.phpfreaks.com/topic/84885-mailer/#findComment-435674 Share on other sites More sharing options...
coalduststar Posted January 17, 2008 Author Share Posted January 17, 2008 Hi again- ok it's drawing out the records grand but the mailer part isn't working- do i have the date in the wrong format? Quote Link to comment https://forums.phpfreaks.com/topic/84885-mailer/#findComment-441900 Share on other sites More sharing options...
adam291086 Posted January 17, 2008 Share Posted January 17, 2008 how can i tell if you dont post any code? Quote Link to comment https://forums.phpfreaks.com/topic/84885-mailer/#findComment-441902 Share on other sites More sharing options...
coalduststar Posted January 17, 2008 Author Share Posted January 17, 2008 LOL- right you are- sorry about that! realised that CURDATE in the sql eliminates the date check thing so i just have to check if the emailyn field is populated but it still won't fire out a mail. <?php ### current date ### $cur_date = date('Y-m-d'); ### Gets page name and stores it to variable ### $currentFile = $_SERVER["PHP_SELF"]; $parts = Explode('/', $currentFile); $page_name1 = $parts[count($parts) - 1]; ### Recordset filtered to page name ### mysql_select_db($database_ownership, $ownership); $query_owner = "SELECT * FROM arts_ownership_history WHERE page_expdate < CURDATE() AND page_name = '$page_name1'"; $owner = mysql_query($query_owner, $ownership) or die(mysql_error()); $row_owner = mysql_fetch_assoc($owner); $totalRows_owner = mysql_num_rows($owner); ### Mail function (if page is out of date?) ### $subject = "Page content expired?"; $text = "Please check the content of the following page- http://www.arts.ulster.ac.uk/".$row_owner['page_name']." as the information/content may be expired. The date set for review of this page was ".$row_owner['page_expdate'].". Please contact the designer responsible for this page (".$row_owner['page_author']."<".$row_owner['page_author_email'].">) to ensure that this page is not removed from the server- Thank You."; if($row_owner['$page_emailyn'] < 0){ mail($row_owner['page_owner_email'], $subject, $text, "From: {$row_owner['page_author']} <{$row_owner['page_author_email']}>"); $row_owner['$emailyn'] = 1; $insertSQL = sprintf("INSERT INTO arts_ownership_history(page_emailyn) VALUES 1"); mysql_select_db($database_ownership, $ownership); $Result1 = mysql_query($insertSQL, $ownership) or die(mysql_error()); } ?> just as an aside- you know the way phpself gets the filename and extension- is there a way to get the entire address "http://...philotest.php"? Cos that would eliminate the fact that more than one record can have the same file name? Quote Link to comment https://forums.phpfreaks.com/topic/84885-mailer/#findComment-441927 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.