Oct
25
Posted on 25-10-2007
Filed Under (Sample Code) by chintan

Here’s how to send an email using PHP scripts (via PHP Mailer class).

PLAIN TEXT

CODE:

require (“phpmailer/class1.phpmailer.php”);

//****

//PLEASE CHANGE THE SETTINGS HERE !!!!

//change settings here

$your_email = “info@example.com”;

$your_smtp = “mail.example.com”;

$your_smtp_user = “info@example.com”;

$your_smtp_pass = “example_password”;

$your_website = “http://example.com”;

//****

//get contact form details

$name = $_POST['name'];

$email = $_POST['email'];

$url = $_POST['url'];

$comments = $_POST['comments'];

$response=”Name: $name\nContents:\n$comments\n”;

$mail = new PHPmailer();

$mail = $mail->SetLanguage(“en”, “phpmailer/language”);

$mail->From = $your_email;

$mail->FromName = $your_website;

$mail->Host = $your_smtp;

$mail->Mailer = “smtp”;

$mail->Password = $your_smtp_pass;

$mail->Username = $your_smtp_user;

$mail->Subject = “$your_website feedback”;

$mail->SMTPAuth = “true”;

$mail->Body = $response;

$mail->AddAddress($your_email,”$your_website admin”);

$mail->AddReplyTo($email,$name);

$mail->AddAttachment(“picture.png”,”picture”);

echo “<p>Thanks for your feedback, <em>$name</em>! We will contact you soon!</p>”;

if (!$mail->Send()) {

echo “<p>There was an error in sending mail, please try again at a later time</p>”;

}

$mail->ClearAddresses();

$mail->ClearAttachments();

the key function of this script is $mail->AddAttachment(“picture.png”,”picture.png”);, where you can add any file as email attachments from your script.

Hopefully this example will help you to create a useful and flexible mail sending php scripts

(0) Comments    Read More   
Oct
25
Posted on 25-10-2007
Filed Under (Tutorial) by chintan

SQL – What’s a Database?

A database is nothing more than an empty shell, like a empty warehouse. It offers no real functionality what so ever, other than holding a name. Tables are the next row of our tree offering a wide scope of functionality. If you follow our warehouse example, a SQL table would be the physical shelving inside our vacant warehouse. Each SQL table is capable of housing 1024 columns (shelves). Depending on the situation, your goods may require reorganization, reselling, or removal. SQL tables can be manipulated in this same way or in any fashion the situation calls for.

SQL – Four Principles of Database Design

When designing and implementing a database, keep in mind these four guidelines.

Atomicity

Your coded statements flow without the constant need to update or “fix” your data.

Consistency

Your statements are either executed 100% or fail 100%, do not implement code that partially works.

Isolation

Keep data files and logs away from public eyes, and limit the number of users with administration access to your database.

Durability

Maintain reliable servers with plenty of storage space and back-up systems that save transactions immediately.

A well thought out database will continue to serve and meet your needs for ages. It is important to plan ahead and really put some thought into what you intend to record in your databases. Keep in mind that tables and databases should maintain some relationship. In many instances it is far more desirable to have several small related tables and databases than one giant one. “Never place your eggs all in one basket.”

The Database Model

Dr. Edgar F. Codd was the founding father of what is known as the relational model of databases. In 1970, he published a groundbreaking article “A Relational Model of Data for Large Shared Data Banks.” Included within the article were 11 rules of relational databases. These rules are as follows (paraphrased).

1. Information Rule

All data in the database should be represented as values in tables.

2. Treatment of NULL Values

Null values must be treated as incomplete data pieces. Nulls are not to be confused with zeros.

3. Guaranteed Access

Every piece of data should be accesible by using the table name, primary key, and a column name.

4. Sublanguage

Having one supported language with a well-defined syntax.

5. Active-Online Relational Catalog

A database is represented at a logical level of tables.

6. Set-level Insertion, Update, and Deletion

System must support set-time insert, update, and deletion operations.

7. Data Independence (Physical)

Alterations to the way data is stored must not alter the application itself.

8. Data Independence (Logical)

Altering tables, columns, and/or rows must not alter the application itself.

9 Updating Views

All views should be updated through the system.

10. Integrity Independence

The language of the database must define integrity rules.

11. No subversion

If the system uses a low level interface to record data, then there must be a higher level interface used when administrating.

The largest of corporation follow these rules of cataloging information to this very day.

Database Driven Web Sites

Today we experience the power of databases throughout the web. Many sites are completely dynamic, meaning the content that is being display is held inside of a table with columns, and columns of information to display. This is quickly becoming the ideal way to host websites. It allows for dynamic content on the fly, user interaction, and webmasters can store information about returning users making way for the site to recognize returning users. Any chance at building rapport with your audience is a great opportunity indeed.

SQL – Platforms

A SQL platform acts as the stage for structure and developing your databases. Several different platforms exist including:

* IBM’s DB2

* MySQL

* Oracle

* Microsoft’s SQL Server

* PostgreSQL

SQL – MySQL and PostgreSQL

MySQL and PostgreSQL are open source database programs rich in functionality and flexibility. They are often the choice of web developers and small businesses simply because they get the job done for a very sensible price. Also they will go anywhere and can operate on nearly every operating system available.

Microsoft’s SQL Server is steadily on the rise in the commercial world gaining popularity slowly. This platform has a GUI “Windows” type interface and is also rich with functionality. A free trial version can be downloaded at the Microsoft web site, however it is only available to Windows users.

SQL – DB2 and Oracle

By far the selection of choice for large corporations is either Oracle or DB2. Companies that have large ties to IBM stick to their DB2 software whereas others have made the switch to Oracle. These systems run on personal computers as well as large company mainframes.

PHP / MySQL Tutorial

MySQL is at present the most popular open source database server in existence. On top of that, it is very commonly used in combination with PHP scripts to create powerful and dynamic server-side applications.

MySQL has been criticized in the past for not supporting all the features of other popular and more expensive Database Management Systems. However, MySQL continues to get better with each release (currently version 5), and it has become widely popular with individuals and businesses of many different sizes.

Why Use a Database?

Databases are most helpful when it comes to storing information that fits into logical categories. For example, say that you wanted to store information of all the employees in a company. With a database you can group different parts of your business into separate tables to help store your information logically. Example tables might be: Employees, Supervisors, and Customers. Each table would then contain columns specific to these three areas. To help store information connected to each employee, the Employees table might have the following columns: Hire, Date, Position, Age, and Salary.

Learn MySQL

Before you begin this tutorial you should have a basic knowledge of the information covered in our PHP and HTML tutorials.

This tutorial focuses heavily on using MySQL in a PHP environment. It is aimed at teaching those who have web hosts with PHP and MySQL already installed. If you are unsure, please contact your web host.

MySQL Setup Guide

The easiest way to research with MySQL and PHP is to purchase some space on a shared web host.

even if you can set up MySQL physically on your home PC, it can be rather difficult for a beginner to do, and would require more than a few lessons! If you think you’ve got what it takes, or you’re just mentally unstable, head on over to MySQL.com for more information on installing MySQL yourself.

Setting Up MySQL in Control Panel

There are many different types of control panels that your shared hosting provider may have. This tutorial assumes that you are using the most popular, ControlPanel.

First, find the link that allows you to administer MySQL. Within Control Panel the icon is labeled MySQL Databases. Once there, you will need to do the following before you can start using MySQL.

* Create a new database

* Create a new user with password

* Assign the user to the database

Helpful Tool – phpMyAdmin!

Also supplied by most hosting services is phpMyAdmin (you can also install it anywhere you want, as it’s open source and free). This tool will allow you to view all the MySQL database, tables, and entries, as well as perform SQL queries remotely through a web browser.

Although we will be teaching how to create databases, tables and all other MySQL tasks through PHP, we encourage you to learn about phpMyAdmin. It’s easy-to-use interface will allow you to do many common MySQL tasks quickly and easily, saving you many beginner headaches and helping you understand what’s going on in a more visual manner.

more Database information on www.databasejournal.com

(0) Comments    Read More