olie04 Posted October 15, 2008 Share Posted October 15, 2008 Hey guys, I need some fresh air on this problem. Basically I am building an application for myself to select all Emails from MYSQL database where the date is between something I enter in a form, and another date, and then send an email saying that their account is expired. Whenever I POST the date into PHP, it returns nothing. Yet if I keep the query "SELECT Email FROM Customer" it selects all the emails and sends an email. Here is the code I am working with. The date format that MYSQL is using is 2008-10-14 00:00:00 <!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> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <?php include 'config.inc.php'; if (isset($_POST['expired'])){ $beginDate = $_POST['beginDate']; $endDate = $_POST['endDate']; echo $subject; $query="SELECT Email FROM Customer WHERE UDFDate2 >= $beginDate and UDFDate2 <= $endDate"; $result=mysql_query($query); $num=mysql_num_rows($result); $i=0; while ($i < $num){ $email=mysql_result($result,$i,"Email"); mail($email, $subject, $message, "From: Sender<Sender@sender.com>\nX-Mailer: PHP/" . phpversion()); echo "Email sent to: " . $email . "<br />"; $i++; } } ?> <br /> <form name="email" action="<?=$_SERVER['admin2423.php']?>" method="post"> Begin Date <input name="beginDate" type="text" size="10"> End Date <input name="endDate" type="text" size="10"> <input type="submit" name="expired" value="Email!"> </form> </body></html> I used this code as a skeleton <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <?php include './inc/config.inc.php'; if (isset($_POST['submit'])) { $subject = $_POST['subject']; $message = $_POST['message']; $query="SELECT email FROM users_test"; //Change users_test to users $result=mysql_query($query); $num=mysql_num_rows($result); $i=0; while ($i < $num) { $email=mysql_result($result,$i,"email"); mail($email, $subject, $message, "From: Someone<someone@somewhere.com>\nX-Mailer: PHP/" . phpversion()); echo "Email sent to: " . $email . "<br />"; $i++; } } ?> <br /> <form name="email" action="<?=$_SERVER['email.php']?>" method="post"> Subject <br /> <input name="subject" type="text" size="50" id="subject"><br /><br /> Message <br /> <textarea name="message" cols="50" rows="10" id="message"></textarea> <br /><br /> <input type="submit" name="submit" value="Email!"> </body> </html> Any help would be greatly appreciated. I need to only get past this date problem, then I know I can tackle what kind of message I want to send. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/128628-solved-mysql-results-from-php-date-search/ Share on other sites More sharing options...
MadTechie Posted October 15, 2008 Share Posted October 15, 2008 try this *untested* <?php //2008-10-14 00:00:00 $beginDate = date("Y-m-d H:i:s", strtotime( $_POST['beginDate']));; $endDate = date("Y-m-d H:i:s", strtotime( $_POST['endDate'])); $query="SELECT Email FROM Customer WHERE UDFDate2 BETWEEN '$beginDate' AND '$endDate' "; ?> Quote Link to comment https://forums.phpfreaks.com/topic/128628-solved-mysql-results-from-php-date-search/#findComment-666623 Share on other sites More sharing options...
olie04 Posted October 16, 2008 Author Share Posted October 16, 2008 Thanks very much! That worked perfectly! I was using the strtotime, but I must have been using it wrong. Thank you again! Quote Link to comment https://forums.phpfreaks.com/topic/128628-solved-mysql-results-from-php-date-search/#findComment-666638 Share on other sites More sharing options...
MadTechie Posted October 16, 2008 Share Posted October 16, 2008 You very welcome, can you click solved if that is the case Quote Link to comment https://forums.phpfreaks.com/topic/128628-solved-mysql-results-from-php-date-search/#findComment-666639 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.