Important alert: (current site time 7/15/2013 8:45:51 PM EDT)
 

VB icon

Damian's Database v3

Email
Submitted on: 8/6/2003 4:43:26 PM
By: Damian myerscough  
Level: Intermediate
User Rating: By 3 Users
Compatibility: 5.0 (all versions), Active Perl specific, 4.0 (all versions), 3.0 (all versions), Pre 3.0
Views: 8707
 
     Its A Database which stores Information on your Friends or can be clients very improved from my last one Uses MySQL This is a gotta see!!!!! It Can: Hold Peoples Information, Search Database, Update Database and Send Emails

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
=**************************************
= Name: Damian's Database v3
= Description:Its A Database which stores Information on your Friends or can be clients very improved from my last one Uses MySQL This is a gotta see!!!!! 
It Can: Hold Peoples Information, Search Database, Update Database and Send Emails
= By: Damian myerscough
=
= Inputs:Yeah
=
= Returns:Stores Information in your SQL Database
=
= Assumes:REad the Comments at the top.
=
=This code is copyrighted and has= limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=510&lngWId=6=for details.=**************************************

#!/usr/bin/perl -w
#
# Coded By; Damian Myerscough
# Database; Damian's Database v3
# Member of; LostSideDead
# Website;www.lostsidedead.com
#
# This a a upgraded version of my Database Ill be release a new and
# Better Database in the near Future.
#
# To Install This first Create a Database callled Friedns i.e.
#
# [prompt]$ mysqladmin -h localhost -u root -ppassword create Friends
#
# once you login an goto the Database i.e. use Friends;
# Do the Following;
#
# mysql> CREATE TABLE ABook (
# -> id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
# -> FirstName varchar(40),
# -> Surname varchar(40),
# -> Address TEXT,
# -> Email varchar(60),
# -> PhoneNumber TEXT,
# -> FULLTEXT (FirstName,Surname)
# -> );
#Query OK, 0 rows affected (0.00 sec)
#
# After that you are Ready to go :)
# Enjoy this code.
#
#
#
use DBI;
use Mail::Sender;
my ($dbh, $sth, $dth1, $sth1, $dth2, $sth2, $sth3, $sth4, $sth5, $sth6, $sth7, $sth8);
sub Clear
{
	system("clear");
}
&Clear;
printf("+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+\n");
printf("Damian's Database v3 \n");
printf("Brought to you by; LostSideDead\n");
printf("+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+\n\n");
print"Login: ";
	$username = <STDIN>;
		chop($username);
		
print"password: ";
	$password = <STDIN>;
		chop($password);
sub Add
{
	&Clear;
	print"+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+\n";
	print" Add A Client\n";
	print"+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+\n\n";
	print"Do you wish to continue: \n";
	print"1) Yes\n";
	print"2) No\n\n";
	
	print"Select: ";
		$Select = <STDIN>;
			chop($Select);
	if($Select =~ /\d+/)
	{
		if($Select == 1)
		{
		
			print"Enter Firstname:";
				$Name = <STDIN>;
					chop($Name);
			print"Enter Surname: ";
				$surname = <STDIN>;
					chop($surname);
			print"Enter Address: ";
				$address = <STDIN>;
					chop($address);
			print"Enter Email:";
				$email = <STDIN>;
					chop($email);
			print"Enter Phone Number: ";
				$phone = <STDIN>;
					chop($phone);
			
		&Clear;
		print"+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+\n";
		print"First Name:$Name\n";
		print"Surname: $surname \n";
		print"Address: $address \n";
		print"Email:$email\n";
		print"Phone Number: $phone\n";
		print"+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+\n\n";
		
		print"Is This Correct:\n";
		print"1) Yes \n";
		print"2) No \n";
		
		print"Select: ";
			$NY = <STDIN>;
				chop($NY);
		
		if($NY =~ /\d+/)
		{
			if($NY == 1)
			{
			my $sql = "(\x4E\x55\x4C\x4C, \x22$Name\x22, \x22$surname\x22, \x22$address\x22, \x22$email\x22, \x22$phone\x22)";
			$dbh = DBI->connect("DBI:mysql:host=localhost;database=Friends",
					"root", "Advent3111",
					{PrintError => 0, RaiseError => 1});
			$sth = $dbh->prepare("INSERT INTO ABook VALUES $sql");
			$sth->execute();
			$sth->finish();
			print"$username added successfully\n";
			sleep(2);
			$dbh->disconnect();
			&Clear;
			
			print"Would you Like to Add another Client:\n";
			print" 1) Yes \n";
			print" 2) No \n";
			
			print"Selection: ";
				$SELECT = <STDIN>;
					chop($SELECT);
			
			if($SELECT =~ /\d+/)
			{
				if($SELECT == 1)
				{
					&Clear;
					&Add;
				}elsif($SELECT == 2)
				{
					&Clear;
					&Menu;
				}else{
					print"Unknown Digit.\n";
				}
			}else{
				print"Select a Digit.\n";
				sleep(2);
				&Add;
			}
			
			
			}elsif($NY == 2)
			{
				&Clear;
				&Add;
			
			}else{
				
				print"Unknown Digit.\n";
				sleep(2);
				&Add;
				
			}
			
		}else{
		
			&Clear;
			print"Error Please Select a Digit.\n";
			sleep(2);
			&Add;
		}
		
					
		
		}elsif($Select == 2)
		{
		
			&Clear;
			&Menu;
		
		}else{
		
			print"Uknown Digit. \n";
			sleep(2);
			&Add;
			
		}
	
	}else{
	
		print"Enter a Digit.\n";
		sleep(2);
		&Add;
	}
	
}
sub Search
{
	&Clear;
	print"+~~~~~~~~~~~~~~~~~~~+\n";
	print"Client Search \n";
	print"+~~~~~~~~~~~~~~~~~~~+\n\n";
	print"Enter First Name: ";
		$FirstName = <STDIN>;
			chop($FirstName);
			
			
	
	$dbh = DBI->connect("DBI:mysql:host=localhost;database=Friends",
			"root", "Advent3111",
			{PrintError => 0, RaiseError => 1});
			
			
		$sth2 = $dbh->prepare("SELECT * FROM ABook WHERE FirstName LIKE \x22\%$FirstName\x22");
		$sth2->execute();
		
		while(my @Results = $sth2->fetchrow_array())
		{
			print"Found $FirstName.\n";
			sleep(2);
			&Clear;
			$Date = gmtime();
			
			print"+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+\n";
			print"+ Todays Date: $Date+\n";
			print"+ user ID: $Results[0]+\n";
			print"+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+\n";
			print"+ Surname:$Results[2]\n"; 
			print"+ Firstname: $Results[1]\n";
			print"+ Address:$Results[3]\n";
			print"+ Tel Number: $Results[5]\n";
			print"+ Email: $Results[4]\n";
			print"+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+\n\n";
			
			print"Would you like to Search Again:\n";
			print"1) Yes \n";
			print"2) No \n\n";
			print"Selection: ";
				$Select = <STDIN>;
					chop($Select);
			
			if($Select =~ /\d+/)
			{
				if($Select == 1)
				{
					&Clear;
					&Search;
				
				}elsif($Select == 2)
				{
				
					&Clear;
					&Menu;
					
				}else{
					print"Digit you entered is too big. \n";
					sleep(2);
					&Clear;
					&Search;
				}
					
			
			}else{
				print"Enter Digit\n";
			}
			
			
		}
		
		$sth2->finish();
}
		
sub Update
{
	&Clear;
	print"+~~~~~~~~~~~~~~~~~~~~~~~~~~~+\n";
	print" Update Client Information \n";
	print"+~~~~~~~~~~~~~~~~~~~~~~~~~~~+\n\n";
	
	print"Field you Can Update: \n";
	print" [1] id \n";
	print" [2] FirstName\n";
	print" [3] Surname \n";
	print" [4] Address \n";
	print" [5] Email\n";
	print" [6] PhoneNumber \n\n";
	
	print"Selection: ";
		$Select = <STDIN>;
			chop($Select);
			
	if($Select =~ /\d+/)
	{
		if($Select == 1)
		{
			
			print"Enter ID To Replace: ";
				$RID = <STDIN>;
					chop($RID);
			
			print"Replace ID with: ";
				$ID = <STDIN>;
					chop($ID);
			if($ID =~ /\d+/)
			{
			
			$dbh = DBI->connect("DBI:mysql:host=localhost;database=Friends",
					"root", "Advent3111",
					{PrintError => 0, RaiseError => 1});
					
			$sth3 = $dbh->prepare("UPDATE ABook SET id=('$ID\') WHERE id='$RID\'");
			$sth3->execute();
			$sth3->finish();
			print"$RID Has Been Successfully Replace with $ID\n";
			sleep(2);
			$dbh->disconnect();
			&Menu;
			
			}else{
				print"Enter a Digit \n";
				sleep(2);
				&Update;
			}
			
		}elsif($Select == 2)
		{
			print"Enter Old Name: ";
				$Name = <STDIN>;
					chop($Name);
			
			print"New Name: ";
				$New = <STDIN>;
					chop($New);
					
			$dbh = DBI->connect("DBI:mysql:host=localhost;database=Friends",
					"root", "Advent3111",
					{PrintError => 0, RaiseError => 1});
										
			$sth4 = $dbh->prepare("UPDATE ABook SET FirstName=('$New\') WHERE FirstName='$Name\'");
			$sth4->execute();
			$sth4->finish();
			print"$Name Has Been Successfully Replace with $New\n";
			sleep(2);
			$dbh->disconnect();
			&Menu;
			
		}elsif($Select == 3)
		{
			print"Enter Old Surname: ";
				$SName = <STDIN>;
					chop($Name);
			
			print"New Surname: ";
				$SNew = <STDIN>;
					chop($New);
					
			$dbh = DBI->connect("DBI:mysql:host=localhost;database=Friends",
					"root", "Advent3111",
					{PrintError => 0, RaiseError => 1});
										
			$sth5 = $dbh->prepare("UPDATE ABook SET FirstName=('$SNew\') WHERE Surname='$SName\'");
			$sth5->execute();
			$sth5->finish();
			print"$SName Has Been Successfully Replace with $SNew\n";
			sleep(2);
			$dbh->disconnect();
			&Menu;
		
		}elsif($Select == 4)
		{
			print"Enter Old Address: ";
				$AName = <STDIN>;
					chop($Name);
			
			print"Enter New Address: ";
				$ANew = <STDIN>;
					chop($New);
					
			$dbh = DBI->connect("DBI:mysql:host=localhost;database=Friends",
					"root", "Advent3111",
					{PrintError => 0, RaiseError => 1});
										
			$sth6 = $dbh->prepare("UPDATE ABook SET Address=('$ANew\') WHERE Address='$AName\'");
			$sth6->execute();
			$sth6->finish();
			print"$AName Has Been Successfully Replace with $ANew\n";
			sleep(2);
			$dbh->disconnect();
			&Menu;
		
		}elsif($Select == 5)
		{
			print"Enter Old Email: ";
				$EName = <STDIN>;
					chop($Name);
			
			print"Enter New Email: ";
				$ENew = <STDIN>;
					chop($New);
					
			$dbh = DBI->connect("DBI:mysql:host=localhost;database=Friends",
					"root", "Advent3111",
					{PrintError => 0, RaiseError => 1});
										
			$sth7 = $dbh->prepare("UPDATE ABook SET Email=('$ENew\') WHERE Email='$EName\'");
			$sth7->execute();
			$sth7->finish();
			print"$EName Has Been Successfully Replace with $ENew\n";
			sleep(2);
			$dbh->disconnect();
			&Menu;
			
		}elsif($Select == 6)
		{
			print"Enter Old Phone Number: ";
				$PName = <STDIN>;
					chop($Name);
			
			print"Enter New Phone Number: ";
				$PNew = <STDIN>;
					chop($New);
					
			$dbh = DBI->connect("DBI:mysql:host=localhost;database=Friends",
					"root", "Advent3111",
					{PrintError => 0, RaiseError => 1});
										
			$sth8 = $dbh->prepare("UPDATE ABook SET PhoneNumber=('$PNew\') WHERE PhoneNumber='$PName\'");
			$sth8->execute();
			$sth8->finish();
			print"$PName Has Been Successfully Replace with $PNew\n";
			sleep(2);
			$dbh->disconnect();
			&Menu
			
		}else{
			print"Unknown Digit.\n";
		
		}
	
	}else{
		print"Enter a Digit. \n";
		sleep(2);
		&Update;
	}
	
	
	
	
	
	
}
sub Email
{
	print"Enter First Name: ";
		$FirstName = <STDIN>;
			chop($FirstName);
			
			
		$dbh1 = DBI->connect("DBI:mysql:host=localhost;database=Friends",
				 "root", "Advent3111",
				 {PrintError => 0, RaiseError => 1});
			$sth1 = $dbh1->prepare("SELECT Email FROM ABook WHERE FirstName LIKE \x22\%$FirstName\x22");
			$sth1->execute();
			while(my @Result = $sth1->fetchrow_array())
			{
				print"Searching..\n";
				sleep(2);
			
			
			
			print"+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+\n";
			print" Found: $FirstName\n";
			print" Email: @Result\n";
			print"+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+\n\n";
			print"Would you Like to Send The Email:\n";
			print" 1) Yes \n";
			print" 2) No \n\n";
			
			print"Selection: ";
				$Select = <STDIN>;
					chop($Select);
					
			if($Select =~ /\d+/)
			{
				if($Select == 1)
				{
					print"Email From: ";
						$Email = <STDIN>;
							chop($Email);
				
					print"Email Subject:";
						$To = <STDIN>;
							chop($To);
							
					print"Enter a Small Message: ";
						$Message = <STDIN>;
							chop($Message);
				
				
				$sender = new Mail::Sender
			 				{smtp => '127.0.0.1',
							 from => "$Email"};
				$sender->MailMsg({to => "@Result",
						subject => "$To",
						msg => "$Message",
		 				 });
				
				&Clear;
				print"Message Successfully Sent to: @Result \n";
				sleep(3);
				&Menu;
				
				}elsif($Select == 2)
				{
					&Menu;
				
				}else{
					print"Error Enter a Digit.\n";
				}
			
			}else{
				print"Enter Digit\n";
			}
	}
	
			$sth1->finish();
			$dbh1->disconnect();
	
	
}
if($username eq 'Damian' && $password eq 'Damian')
{
sub Menu
{	
	&Clear;
	print"Welcome $username \n\n";
	print"1) Add Client \n";
	print"2) Search Client\n";
	print"3) Update Client\n";
	print"4) Email Client\n";
	print"5) Quite\n\n";
	&Choose;
	
}
sub Choose
{	
	print"Select: ";
		$Select = <STDIN>;
			chop($Select);
	if($Select =~ /\d+/)
	{
		if($Select == 1)
		{
			&Add;
		
		}elsif($Select == 2)
		{
			&Search;
	
		}elsif($Select == 3)
		{
			&Update;
		
		}elsif($Select == 4)
		{
			&Email;
		
		}elsif($Select == 5)
		{
			print"Thanks For trying this Database.\n";
			sleep(2);
			exit(0);
		}
	}else{
		print"Select a Digit\n";
		sleep(2);
		&Menu;
	}
}		
	&Clear;
	&Menu;	
	
}else{
	
	print"Error Login Failed.\n";
	
}


Other 35 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

8/15/2003 12:21:11 PMJason Myerscough

Damo, it would be better to add more comments to your source code and u need to make my guest book.
(If this comment was disrespectful, please report it.)

 
8/16/2003 9:04:51 AMJason Myerscough

one thing i forgot to mention stop using massive images as screen shots they take ages to load up
(If this comment was disrespectful, please report it.)

 
8/18/2003 2:28:18 PM

:), my boy has gone a far way..
<3 dude!
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.