Jump to content

Code e-mails me twice


BelowZero

Recommended Posts

I'm using this code to create and populate a database.

It gets a bit involved as it is creating a series of times for every day in the year.

The database gets created and populated just fine, however I have 2 quirks I can't figure out.

First, I am creating a separate file to store connection creds to the database. The file gets created and holds the correct information, but as I am using the program, somehow the file is getting overwritten with blank spaces, making it impossible to connect to the database.

2nd, the program sends me an e-mail when the database is created. Problem is I'm getting 2 e-mails about 20 minutes apart. 1 with all the correct information and 1 blank.

I'm thinking maybe these problems are related??? Like the program is trying to run itself twice or is getting called twice.

Once the program runs, it never gets called again in any other part of the program code. Any ideas? Thanks.

<?php	

$coursename = $_POST["coursename"];
$websiteurl = $_POST["websiteurl"];
$email = $_POST["email"];
$otime = $_POST["opentime"];
$ctime = $_POST["closetime"];
$interval = $_POST["interval"];
$year = $_POST["year"];
$server = $_POST["server"];
$username = $_POST["username"];
$password = $_POST["password"];
$userpassword = $_POST["userpassword"];

//--Creates a file to store Login Information--\\
$data = <<<DATA
<?php
\$server = "$server";
\$username = "$username";
\$password = "$password";
?>
DATA;

file_put_contents("databasedata.php", $data);

//--Connect to the Server--\\     	
mysql_connect("$server", "$username", "$password");

//--Create the Database--\\
mysql_query("CREATE DATABASE IF NOT EXISTS TeeTimes");

mysql_select_db("TeeTimes");

//--Create the Tables--\\    
mysql_query("CREATE TABLE IF NOT EXISTS CourseInfo
(
Course_ID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(Course_ID),
CourseName varchar(40) NOT NULL default '',
HomePage varchar(50)NOT NULL default '',
Email varchar(50) NOT NULL default '',
Password varchar(20) NOT NULL default ''
)");

mysql_query("CREATE TABLE IF NOT EXISTS Daysheets$year
(
Sheet_ID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(Sheet_ID),
Date date NOT NULL,
Time time NOT NULL,
Player1 varchar(30) NOT NULL default '',
Cart1 varchar(3) NOT NULL default '',
Player2 varchar(30) NOT NULL  default '',
Cart2 varchar(3) NOT NULL default '',
Player3 varchar(30) NOT NULL  default '',
Cart3 varchar(3) NOT NULL default '',
Player4 varchar(30) NOT NULL default '',
Cart4 varchar(3) NOT NULL default '',
Player5 varchar(30) NOT NULL default '',
Cart5 varchar(3) NOT NULL default '',
Men smallint(4) NOT NULL default 0,
Women smallint(4) NOT NULL default 0,
Guest smallint(4) NOT NULL default 0,
Event varchar(3) NOT NULL default '',
EventName varchar(30) NOT NULL default ''
)");

//***To Populate the Database with Dates and Times***\\         
mysql_query("
INSERT INTO CourseInfo
(CourseName,HomePage,Email,Password)
VALUES('$coursename','$websiteurl','$email','$userpassword')");

$rows = mysql_query("SELECT * FROM Daysheets$year"); 

if ($rows[Date]=="") 
   {  
   $firstday = "$year:01:01 $otime:00:00";
   $firstdate = strtotime($firstday);

   $firsttime = "$year:01:01 $otime:00:00"; 
   $opentime = strtotime($firsttime);

   $lasttime = "$year:01:01 $ctime:00:00";
   $closetime = strtotime($lasttime);

   $time = date("g:i",$opentime);

   $i=1;
   //***To Account For Leap Years***\\
   if ($year == 2012 || $year == 2016 || $year == 2020 || $year == 2024)
   {$n=366;}
   else 
   {$n=365;}

while ($i <= $n)
{
$newday = date("Y-m-d",$opentime);

mysql_query("
INSERT INTO Daysheets$year
(Date,Time)
VALUES('$newday','$time')");

while ($opentime < $closetime)
{
$newtime = strtotime("+$interval minute", $opentime);
$nexttime = date("Y-m-d g:i a",$newtime);

$nextd = date("Y-m-d",$newtime);
$nextt = date("g:i",$newtime);

mysql_query("
INSERT INTO Daysheets$year
(Date,Time)
VALUES('$nextd','$nextt')");

$opentime = strtotime($nexttime);
}

$opentime = strtotime($firsttime);
$newday = strtotime("+$i day", $opentime);
$nextday = date("Y-m-d g:i a",$newday);
$opentime = strtotime($nextday);

$closetime = strtotime($lasttime);
$newday = strtotime("+$i day", $closetime);
$nextday = date("Y-m-d g:i a",$newday);
$closetime = strtotime($nextday);

$i++;
}
}
mysql_close();

//--Send Information for Safekeeping--\\
$to = "someone@somewhere.org";
$subject = "Tee Time Maker User Info";
$message = 
"Course Name:' '$coursename \n 
Website: ' '$websiteurl \n 
E-Mail: ' '$email \n 
Password: ' '$userpassword";
mail($to, $subject, $message, "From: $coursename <$email>");

//--Redirect user to the newly created site--\\
header("Location: /teetimes/adminteetimes.php");

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.