g
Printer Friendly Version

editor  
BellaOnline's PHP Editor
 

Personal Activities Calendar Program Use the strtotime and mysql_select_db Functions

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!

PHP Site @ BellaOnline
View This Article in Regular Layout

Content copyright © 2013 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 Editor Wanted for details.



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


BellaOnline Editor