logo
g Text Version
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Sports
Travel & Culture
TV & Movies

dailyclick
Bored? Games!
Nutrition
Postcards
Take a Quiz
Rate My Photo

new
European Travel
Action Movies
Bible Basics
Houseplants
Romance Movies
Creativity
Family Travel


dailyclick
All times in EST

Full Schedule
g
g PHP Site

BellaOnline's PHP Editor

g

Personal Activities Calendar Program Use the strtotime and mysql_select_db Functions

Guest Author - Diane Cipollo

At this point in the Personal Activities Calendar Program project, we have programmed the ActivityEntry.php3 script to send the Activity Entry Form to the web browser when it is needed and to check for missing data and respond if necessary. Now we have finally arrived at the place in the ActivityEntry.php3 script where we are ready to process the form data for a new activity entry. Because we have passed all the previous test, we can assume that the data is ready to post into the database. (See note at bottom of page about security testing.)

You should have already created a config.php3 file. Also, you will need to refresh your memory about the strtotime( ) function and the mysql_connect( ) function. If you need help with these tasks, follow the link below and do that now. With that completed, we are ready to write the section of the ActivityEntry.php3 script that will create a new record in the activities table. You will remember that we created this activities table in the first tutorial of the project. Here are the next two steps we need to add to the ActivityEntry.php3 script.

1. Use the strtotime( ) function to create a Unix timestamp for the beginning and ending time/date for the new activity. We will create two new variables to hold this information.

2. Use the mysql_connect( ) function to identify yourself to the MySQL server and add a mysql_select_db function to identify what database we wish to use.

Unix Timestamp

In a previous tutorial, you learned how to use the strtotime( ) function to create Unix timestamps. Now we will use this function to create two timestamps for the beginning and ending time/date for the new activity. We will store these timestamps in two new variables that we will call $act_start_time and $act_end_time.

You will remember that in the CheckData.php3 file, we stored the new activity's time/date information (obtained from the web form) in the following variables.

Date and time the activity begins
$pass_act_month_1
$pass_act_day_1
$pass_act_year_1
$pass_act_hour_1

Date and time the activity ends
$pass_act_month_2
$pass_act_day_2
$pass_act_year_2
$pass_act_hour_2

We will use the strtotime( ) statement to create a Unix timestamp from these variables. Then we can store these timestamps in the database. As you can see, the variables are separated by a space and placed within quotation marks.

$act_start_time = strtotime("$pass_act_month_1
$pass_act_day_1 $pass_act_year_1
$pass_act_hour_1");

$act_end_time =strtotime("$pass_act_month_2
$pass_act_day_2 $pass_act_year_2
$pass_act_hour_2");
Note--The arrow indicates that the code is wrapped to a second line and should really be all on one line.

Next →




A Custom Configuration File For PHP Programs
How to Connect to the MySQL Server with the PHP mysql_connect Function

The PHP Strtotime Function

This site needs an editor - click to learn more!

Add Personal+Activities+Calendar+Program+%96+Use+the+strtotime+and+mysql%5Fselect%5Fdb+Functions to Twitter Add Personal+Activities+Calendar+Program+%96+Use+the+strtotime+and+mysql%5Fselect%5Fdb+Functions to Facebook Add Personal+Activities+Calendar+Program+%96+Use+the+strtotime+and+mysql%5Fselect%5Fdb+Functions to MySpace Add Personal+Activities+Calendar+Program+%96+Use+the+strtotime+and+mysql%5Fselect%5Fdb+Functions to Del.icio.us Digg Personal+Activities+Calendar+Program+%96+Use+the+strtotime+and+mysql%5Fselect%5Fdb+Functions Add Personal+Activities+Calendar+Program+%96+Use+the+strtotime+and+mysql%5Fselect%5Fdb+Functions to Yahoo My Web Add Personal+Activities+Calendar+Program+%96+Use+the+strtotime+and+mysql%5Fselect%5Fdb+Functions to Google Bookmarks Add Personal+Activities+Calendar+Program+%96+Use+the+strtotime+and+mysql%5Fselect%5Fdb+Functions to Stumbleupon Add Personal+Activities+Calendar+Program+%96+Use+the+strtotime+and+mysql%5Fselect%5Fdb+Functions to Reddit




RSS | Related Articles | Editor's Picks Articles | Top Ten Articles | Previous Features | Site Map


For FREE email updates, subscribe to the PHP Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor


Content copyright © 2014 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.

g


g features
Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor