PHP3 Getting Started tutorial MySQL Database interface

Source: Internet
Author: User
Tags insert mail connect mysql variables query mysql database

The following is how to use PHP3.0 and MySQL to construct a database Web application.

The following functions related to MySQL, must be installed on the server after the installation and debugging of MySQL before it can run. If you're not familiar with MySQL, it's a good idea to look at the article first.

PHP acts as a middleman between the database server and the Web browser, explaining the order of one party to the other and then sending back the results. It is the possibility of this communication that makes many tasks possible. such as online surveys, online shopping, personalized sites and so on, all with the help of this technology.

This interaction begins with a connection to the MySQL database and is implemented using the following command:

Syntax: int mysql_connect (string hostname, string Username, string password);

* hostname-the host name where the database server resides

* Username-user name used to connect to the MySQL database.

* Password-the user's corresponding password.

* The shape value returned, that is, a connection number. When the connection number is positive, the connection is successful, while the negative indicates that the connection failed.

Likewise, all of these commands must be placed between "".

Then go back to the processing of our user information. After the following several commands are executed, a information table is established in the MySQL database:
mysql> CREATE TABLE Information (
-> name VARCHAR (25),
-> Email VARCHAR (25),
-> Choice VARCHAR (8));


Now, if we want to insert some user information into the table, we can modify just the email.php3 script:



/* This script is used to process variables from moreinfo.html files.

/* Define a number of related variables * *

$hostname = "devshed";
$username = "MyUserName";
$password = "MyPassword";
$dbName = "Mydbname";

/* MySQL table for storing user data * *
$userstable = "Information";

/* Site Director's email address * *
$adminaddress = "administration@buy.com";

/* Establish a connection to the database * *
Mysql_connect ($hostname, $username, $password) or DIE ("Unable to CONNECT to database");

@mysql_select_db ("$dbName") or Die ("Unable to select database");

PRINT "< center>";
PRINT "Hello, $name."
PRINT "< br>< br>";
PRINT "Thank you for your participation < br>< br>";
PRINT "We will issue validation information to $email";
PRINT "</center>< br>< br>";

* * Send the relevant message * *
Mail ("$email", "Your Request for Information",
"$name \nthank for your interest!\n
We sell fresh corn daily over the internet!
Place your in http://www.buy.com,
and receive a FREE package of $preference! ");

Mail ("$adminaddress",
"Visitor Request for info.",
"$name requested for information.\n

The email address is $email. \ Visitor prefers $preference. ");

/* Insert the information into the table * *
$query = "INSERT into $userstable VALUES (' $name ', ' $email ', ' $preference ')";

$result = mysql_query ($query);

PRINT "Your information has been inserted into our database, we will be able to bring you a better service." ";

/* Close Database connection/*
Mysql_close ();
?>

-->



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.