Sample ActivityEntry.php3 Code - Personal Activities Calendar Program


<?php

//Call config.php3 and ActivityEntryForm.php3
require_once('config.php3');
require_once('ActivityEntryFormStep3.php3');

//If the $_POST submit is empty, set variables to null, call function to display form for the first time
if(empty($_POST['submit']))
{ $pass_act_title = "";
$pass_act_desc = "";
$pass_act_month_1 = "";
$pass_act_day_1 = "";
$pass_act_year_1 = "";
$pass_act_hour_1 = "";
$pass_act_month_2 = "";
$pass_act_day_2 = "";
$pass_act_year_2 = "";
$pass_act_hour_2 = "";
$pass_act_status = "";

//Set the $error_message to null
$error_message = "";

Activity_Entry_Form( $error_message, $pass_act_title, $pass_act_desc, $pass_act_month_1, $pass_act_day_1, $pass_act_year_1, $pass_act_hour_1,
$pass_act_month_2, $pass_act_day_2, $pass_act_year_2, $pass_act_hour_2, $pass_act_status );
}

//If the $_POST submit is not empty, include CheckData.php3, which will check for missing form data
else {

include ("CheckData.php3");

//If $error_message has been changed to yes, call function to print form again
if ($error_message == "yes")
{
Activity_Entry_Form( $error_message, $pass_act_title, $pass_act_desc, $pass_act_month_1, $pass_act_day_1, $pass_act_year_1, $pass_act_hour_1,
$pass_act_month_2, $pass_act_day_2, $pass_act_year_2, $pass_act_hour_2, $pass_act_status );
}

//If $error_message is still set to no, process data
else {

//Set Unix timestamps for beginning and ending date and time for activity

$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");

//Identify yourself to MySQL server and choose a database

$connection = @mysql_connect("$host", "$username", "$password") or die ("Could not connect to the database at this time. Please try later.");
$db = @mysql_select_db($name_of_database, $connection) or die("Could not connect to the database at this time. Please try later.");

//Create a new record and test for error

$sql_send = "INSERT INTO activities (act_ID, act_title, act_desc, act_timestamp_1, act_timestamp_2, act_status) values (' ', '$pass_act_title', '$pass_act_desc', '$act_start_time', '$act_end_time', '$pass_act_status')";

$result = @mysql_query($sql_send, $connection) or die ("Could not connect to the database at this time. Please try later.");

}

}
?>