PDA

View Full Version : Displaying data according to date


bddotnet
10-13-07, 11:08 AM
I have this code:


<?
include "";

$connect=mysql_connect($database,$username,$passwo rd);
$result=mysql_select_db($database) or die( "This database is not working");
$current_date = date("Y-m-d");

$list_query = mysql_query("SELECT * FROM announcements WHERE LEFT(eventstart,10) >= 'current_date' ORDER BY eventend DESC");

echo '
Today\'s Date: $current_date
<ul>
';

while ( $data = mysql_fetch_array($list_query) ) {

echo "
<li>$data[event]$data[entry]</li>
";

}

echo "

</ul>

";
?>


Why am I not seeing the announcements that I have put into the table on www.okfqhr.com/index_new.php?

Thanks!

Neat Pete
10-14-07, 02:06 AM
Where you have 'current_date' you are probably not getting the current date into the SQL statement correctly.

When testing, always echo your SQL statement back. It's often a surprise. Rem it out with // once it seems reliable.

You need something like...

$SQL = "SELECT * FROM announcements WHERE LEFT(eventstart,10) >= ";
$SQL = $SQL.$current_date;
$SQL = $SQL." ORDER BY eventend DESC";
echo 'SQL Statement to get Announcements: '.$SQL;
$list_query = mysql_query($SQL);

Question for the whole forum: Which is better - a clever one-liner that does not work or several lines that work and are easily seen to be correct?

BerksWebGuy
10-14-07, 02:30 AM
Also, are you you storing the date as a datetime field...or do you have it in something like a varchar field?

bddotnet
10-14-07, 10:57 AM
I found the error. It was much simpler than expected. The $current_date variable isn't stored. The $date variable is stored as a DATE.

I had:
echo '
<li>$date</li>
';

when I should have had:

echo "
<li>$date</li>
";

Thanks guys!

Neat Pete
10-14-07, 03:47 PM
How does that SQL statement work with current_date instead of $current_date ????

bddotnet
10-15-07, 04:44 AM
Here is what I finally came up with and used on the page:


<?
//include connection information via php file
include "";

//connect to database
$connect=mysql_connect($database,$username,$passwo rd);
$result=mysql_select_db($database) or die( "This database is not working");
$current_date = date("Y-m-d");

//query the database table
$list_query = mysql_query("SELECT * FROM announcements WHERE eventend >= current_date ORDER BY eventend DESC");

//echo the results onto the page
echo "
<ul>
";

while ( $data = mysql_fetch_array($list_query) ) {

echo "
<li>$data[event]$data[entry]</li>
";

}

echo "

</ul>

";
?>

Neat Pete
10-15-07, 07:52 AM
Many thanks, I learn something new every day. But is "current_date" a system variable in MySQL, or is it a parameter passed in from PHP?

bddotnet
10-15-07, 09:32 AM
You're welcome!

I do not know all there is to know about PHP, MySQL and how they interact, but I do know it is a variable passed from PHP. You can name it anything as long as the date("Y-m-d"); is set.

Neat Pete
10-15-07, 02:29 PM
Thanks. It's a parameter in an SQL query set directly from a PHP variable. But the $ sign is omitted. Nifty.

bddotnet
10-16-07, 12:42 AM
You're welcome. Thanks for the clarification.

Now, I have a question for you. If I have a form that when the user clicks Submit, it inserts the data into a MySQL database table...how can I (at the same time in the same PHP script) email the form results to the user AND to the owner of the site using PHP (mail) function?

Thanks!

HalfaBee
10-16-07, 05:15 AM
You could use 2 mail() calls or use a BCC header in one mail function.

Neat Pete
10-16-07, 07:34 AM
It's for a community group. I do it with two calls to mail, I don't sent the same message with bcc:

(1) The form has fields for the person to enter
(a) CallerEmail
(b) Subject
(c) Message

(2) These three fields are put thru a Spam testing programme that looks for nasty things, especially efforts to broadcast spam using their own bcc: and cc: headers, etc etc. Their email address must contain one dot at least and one "at" symbol. If it's spam it goes in the bin without acknowledgment, but the next page displayed is a bogus error message code to annoy them, and without instructions on what to do next. As well, all three boxes left blank is taken as spam. Messages without an email address are forwarded as "anon" and are not answered of course. Messages with neither Message nor Subject must be spam by definition.

(3) Send a thank-you email
To: The caller email address off the form
From: The email address of the community group
Subject: Contacting the Community Group
Message: Thank you for your message. It has been passed on for attention.

(4) Relay the message for attention
To: The president (for attention and an answer)
From: The caller on the form
Subject: "Message received via the web site"
Message:
Their Subject from the form
plus
A friendly greeting from me and a ruled line
plus
Message off the form
plus
A ruled line, and all the details of their computer and IP address as available in PHP variables.

Hope this helps put some icing on the cake. There is heaps of stuff on sending the actual emails at www.php.net as well as on this forum.

bddotnet
10-16-07, 08:09 AM
OK. I like what your script does. Could you post it if you don't mind me using it?

Neat Pete
10-16-07, 08:46 AM
OK, I'll put it up somewhere where you can download it. I'll make it .txt not .php so you can save it. You'll need the HTM file as well to see how it works. There are two files, currently called message.htm and message.php. They are currently running under PowWeb's PHP4 not PHP5.

bddotnet
10-16-07, 09:06 AM
OK. Thanks!

Neat Pete
10-16-07, 08:00 PM
Here we go! Download and save these two files...

http://www.kittyandthealleycats.com/contacts/messagehtm.htm
http://www.kittyandthealleycats.com/contacts/messagephp.txt

Rename these files to message.htm and message.php.

Edit both files to have your name where it currently says Community Group.

Edit message.php to have your email address to receive the flakey emails, and the email address of the person who will get the good messages.

Upload both files to the same folder on your own web page and test.

Notice how it's simple and uncluttered, and the focus lands in the box ready to start typing. Never distract your users from sending you a message.

Suggestions for improvements very welcome.

PS: If it's functioning well, turn off the display of error messages.

bddotnet
10-16-07, 11:49 PM
How would I modify this to email the results of a form to two persons (the sender and recipient)?

HalfaBee
10-16-07, 11:59 PM
change this line
mail ( $EmailTo, $Subject, $Message, 'From: '.$EmailFrom );

to

mail ( $EmailTo, $Subject, $Message, 'From: '.$EmailFrom."\r\nBcc: $extra_email" );

bddotnet
10-17-07, 12:09 AM
So, let's say I have a page where a user inputs information into a form. When the user clicks Submit, it inserts the info into a database table.

If I add:

mail ( $EmailTo, $Subject, $Message, 'From: '.$EmailFrom."\r\nBcc: $extra_email" );

to the line just before the mysql_close statement, that would email the results to the two email addresses, correct, as long as I put the correct values that correspond to the two email addresses?

bddotnet
10-17-07, 12:12 AM
Or would this work (which is what I have now)?


//Email the form data to two people
//form fields
$show = $_POST['show'];
$horse = $_POST['horse'];
$horse_fqhr = $_POST['horse_fqhr'];
$coggins = $_POST['coggins'];
$birth_yr = $_POST['birth_yr'];
$gender = $_POST['gender'];
$owner = $_POST['owner'];
$o_fqhr = $_POST['o_fqhr'];
$o_expiration = $_POST['o_expiration'];
$o_address = $_POST['o_address'];
$o_city = $_POST['o_city'];
$o_state = $_POST['o_state'];
$o_zip = $_POST['o_zip'];
$o_phone = $_POST['o_phone'];
$o_email = $_POST['o_email'];
$y_dob = $_POST['y_dob'];
$y_rel = $_POST['y_rel'];
$conf_class = $_POST['conf_class'];
$vy_conf = $_POST['vy_conf'];
$vy_speed = $_POST['vy_speed'];
$vy_ranch = $_POST['vy_ranch'];
$vy_show = $_POST['vy_show'];
$va_conf = $_POST['va_conf'];
$va_cow = $_POST['va_cow'];
$va_show = $_POST['va_show'];
$va_speed = $_POST['va_speed'];
$va_ranchone = $_POST['va_ranchone'];
$va_ranchtwo = $_POST['va_ranchtwo'];
$vo_conf = $_POST['vo_conf'];
$vo_cow = $_POST['vo_cow'];
$vo_show = $_POST['vo_show'];
$vo_speed = $_POST['vo_speed'];
$vo_ranchone = $_POST['vo_ranchone'];
$vo_ranchtwo = $_POST['vo_ranchtwo'];
$stall = $_POST['stall'];
$shavings = $_POST['shavings'];
$rv = $_POST['rv'];
$fcc = $_POST['fcc'];
$scc = $_POST['scc'];
$adyf = $_POST['adyf'];
$membership = $_POST['membership'];
$one = $_POST['one'];
$two = $_POST['two'];
$three = $_POST['three'];
$four = $_POST['four'];
$five = $_POST['five'];
$six = $_POST['six'];
$seven = $_POST['seven'];
$eight = $_POST['eight'];
$nine = $_POST['nine'];
$ten = $_POST['ten'];
$eleven = $_POST['eleven'];
$twelve = $_POST['twelve'];
$thirteen = $_POST['thirteen'];
$fourteen = $_POST['fourteen'];
$fifteen = $_POST['fifteen'];
$sixteen = $_POST['sixteen'];
$seventeen = $_POST['seventeen'];
$eighteen = $_POST['eighteen'];
$nineteen = $_POST['nineteen'];
$twenty = $_POST['twenty'];
$twentyone = $_POST['twentyone'];
$twentytwo = $_POST['twentytwo'];
$twentythree = $_POST['twentythree'];
$twentyfour = $_POST['twentyfour'];
$twentyfive = $_POST['twentyfive'];
$twentysix = $_POST['twentysix'];
$twentyseven = $_POST['twentyseven'];
$twentyeight = $_POST['twentyeight'];
$twentynine = $_POST['twentynine'];
$thirty = $_POST['thirty'];
$thirtyone = $_POST['thirtyone'];
$thirtytwo = $_POST['thirtytwo'];
$thirtythree = $_POST['thirtythree'];
$thirtyfour = $_POST['thirtyfour'];
$thirtyfive = $_POST['thirtyfive'];
$thirtysix = $_POST['thirtysix'];
$thirtyseven = $_POST['thirtyseven'];
$thirtyeight = $_POST['thirtyeight'];
$thirtynine = $_POST['thirtynine'];
$forty = $_POST['forty'];
$fortyone = $_POST['fortyone'];
$fortytwo = $_POST['fortytwo'];
$fortythree = $_POST['fortythree'];
$fortyfour = $_POST['fortyfour'];
$fortyfive = $_POST['fortyfive'];
$fortysix = $_POST['fortysix'];
$fortyseven = $_POST['fortyseven'];
$fortyeight = $_POST['fortyeight'];
$fortynine = $_POST['fortynine'];
$fifty = $_POST['fifty'];
$fiftyone = $_POST['fiftyone'];
$fiftytwo = $_POST['fiftytwo'];
$fiftythree = $_POST['fiftythree'];
$fiftyfour = $_POST['fiftyfour'];
$fiftyfive = $_POST['fiftyfive'];
$fiftysix = $_POST['fiftysix'];
$fiftyseven = $_POST['fiftyseven'];
$fiftyeight = $_POST['fiftyeight'];
$fiftynine = $_POST['fiftynine'];
$sixty = $_POST['sixty'];
$sixtyone = $_POST['sixtyone'];
$sixtytwo = $_POST['sixtytwo'];
$sixtythree = $_POST['sixtythree'];
$sixtyfour = $_POST['sixtyfour'];
$sixtyfive = $_POST['sixtyfive'];
$sixtysix = $_POST['sixtysix'];
$sixtyseven = $_POST['sixtyseven'];
$sixtyeight = $_POST['sixtyeight'];
$sixtynine = $_POST['sixtynine'];
$seventy = $_POST['seventy'];
$seventyone = $_POST['seventyone'];
$seventytwo = $_POST['seventytwo'];

// multiple recipients
$to = '$o_email' . ', '; // the person who submitted the form
$to .= 'judgescoordinator@okfqhr.com'; //the president of the association
$to .= 'showsecretary@okfqhr.com'; //the show secretary

// subject
$subject = 'OKFQHR - Onlne Pre-Entry';

// message in a format the show secretary can easily interpret
$message = '
Show Date: $show \n;
<br>
Horse Information: \n;
Horse: $horse \n;
FQHR Registration #: $horse_fqhr \n;
Coggins Date: $coggins \n;
Birth Year: $birth_yr \n;
Gender: $gender \n;
<br>
Owner Information: \n;
Owner: $owner \n;
Owner FQHR#: $o_fqhr \n;
Expiration Date: $o_expiration \n;
Address: $o_address \n;
City: $o_city \n;
State: $o_state \n;
Zip: $o_zip \n;
Phone: $o_phone \n;
Email: $o_email \n;

Exhibitor Information: \n;
Name: $exhibitor \n;
FQHR#: $e_fqhr \n;
Expiration Date: $expiration \n;
Address: $e_address \n;
City: $e_city \n;
State: $e_state \n;
Zip: $e_zip \n;
Phone: $e_phone \n;
Email: $e_email \n;
Youth DOB: $y_dob \n;
Youth Relation: $y_rel \n;

Classes: \n;

Confirmation Classes: \n;
Confirmation Class: $conf_class \n;
Class: $thirty \n;
Class: $thirtysix \n;
Class: $fortythree \n;
Class: $fortyfour \n;

Cattle Classes: \n;
Class: $five \n;
Class: $six \n;
Class: $seven \n;
Class: $fourteen \n;
Class: $fifteen \n;
Class: $sixteen \n;
Class: $twenty \n;

Show Classes: \n;
Class: $one \n;
Class: $two \n;
Class: $three \n;
Class: $four \n;
Class: $fiftythree \n;
Class: $fiftyfour \n;
Class: $fiftyfive \n;
Class: $fiftysix \n;
Class: $fiftyseven \n;
Class: $fiftyeight \n;
Class: $fiftynine \n;
Class: $sixty \n;

Ranch Horse Classes: \n;
Class: $eight \n;
Class: $nine \n;
Class: $ten \n;
Class: $eleven \n;
Class: $twelve \n;
Class: $thirteen \n;
Class: $nineteen \n;
Class: $twentyone \n;
Class: $twentytwo \n;
Class: $twentythree \n;
Class: $fortyseven \n;
Class: $fortyeight \n;

Speed Events: \n;
Class: $sixtyone \n;
Class: $sixtytwo \n;
Class: $sixtythree \n;
Class: $sixtyfour \n;
Class: $sixtyfive \n;
Class: $sixtysix \n;
Class: $sixtyseven \n;
Class: $sixtyeight \n;
Class: $sixtynine \n;
Class: $seventy \n;
Class: $seventyone \n;
Class: $seventytwo \n;

Team Timed Events: \n;
Class: $seventeen \n;
Class: $eighteen \n;

Non-Sanctioned Classes: \n;
Class: $fortyfive \n;
Class: $fortysix \n;
Class: $fortynine \n;
Class: $fifty \n;
Class: $fiftyone \n;
Class: $fiftytwo \n;

Versatility Youth: $nintyseven \n;
Class: $vy_conf \n;
Class: $vy_speed \n;
Class: $vy_ranch \n;
Class: $vy_show \n;

Versatility Amateur: $nintyeight \n;
Class: $va_conf \n;
Class: $va_cow \n;
Class: $va_show \n;
Class: $va_speed \n;
Class: $va_ranch1 \n;
Class: $va_ranch2 \n;

Versatility Open: $nintynine \n;
Class: $vo_conf \n;
Class: $vo_cow \n;
Class: $vo_show \n;
Class: $vo_speed \n;
Class: $vo_ranch1 \n;
Class: $vo_ranch2 \n;

Additional Fees: \n;
Stall: $stall \n;
Shavings: $shavings \n;
RV Hookup: $rv \n;
1st Cattle Charge: $fcc \n;
2nd Cattle Charge: $scc \n;
All-Day Youth Fee: $adyf \n;

Membership: $membership \n;
';

// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Marilyn Duncan <president@okfqhr.com>' . "\r\n";
$headers .= 'From: $o_name <$o_email>' . "\r\n";
$headers .= 'Cc: Laura Ward <showcoordinator@okfqhr.com>' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);

echo '<center><img src="http://www.okfqhr.com/images/head.jpg"><br>1 entry received. You will receive a confirmation email at the email address you provided.<br><a href="http://www.okfqhr.com">OkFQHR Home</a>'; mysql_close($con)
?>

Neat Pete
10-17-07, 12:53 AM
At the moment it just sends a 'thank-you' to the sender.

As suggested in an earlier post you could do a bcc: or a cc: but this means a bit of reading up.

The quick way is to take this line (it's around about line 250)

mail ( $EmailTo, $Subject, $Message, 'From: '.$EmailFrom );

and add a second line right below it saying...

mail ( $EmailFrom, $Subject, $Message, 'From: '.$EmailTo);

Then rem out the line where it sends the acknowledgement, round about line 277.

I have not tested it, so see how you go.

Neat Pete
10-17-07, 12:56 AM
OOppss, all our postings have crossed in the mail. I was answering number 17 and had not refreshed my display.