Use PHP to implement small-scale website advertisement management

Source: Internet
Author: User
In this example, it is debugged in PHP4 + MySQL + ApacheforWin9x/2000, which consists of two parts: AddNewAd, a program used to add new advertisements. php3 and ShowAd. php3 is stored in the "test/guanggao/" directory under the php file directory of the server. In this example, it was debugged in PHP4 MySQL Apache for Win9x/2000, which contains two parts: AddNewAd, the program used to add new advertisements. php3 and ShowAd. php3 is stored in the "test/guanggao/" directory under the php file directory of the server. Create a sub-directory "adbanner/" to store ad link images in the guanggao directory /". Next we will analyze the data according to the steps below.
  
1. First, create a MySQL database: guanggao
  
In Windows, it is very simple to create a MySQL empty Database. because each database exists in a sub-directory under the mysql/data/directory, therefore, you only need to create a new sub-directory named guanggao in this directory, and there is no table or data in the database.
  
2. create a new advertisement program: AddNewAd. php3
  
Design Concept: first obtain the user's new advertisement information using the form, and then upload the linked image (banner) file to the server's adbanner Directory using the PHP function copy; finally, write the image file name, advertisement URL, clarification, and weighting information into the created MySQL data table ad. The program code is as follows:
  
# AddNewAd. php3 -- add new advertisement #
   Add new advertisement
// Form is used to input New advertisement information and hand it to the following PHP program for processing;
// The larger the weighted value priority, the higher the probability of the image being uploaded to the page. the default value is 1.
  
// PHP program for processing form data;
   // The banner name and link address of the image cannot be blank;
If (banner! = '') & (Url! = '')){
// If the ad link and image name have been applied, you must select another one;
If (file_exists ('adbanner/'. banner_name )){
Echo 'ad Image. banner_name. Applied. please select another one! ';
Exit;
};
// Upload the linked image file name to the adbanner directory;
Copy (banner, 'adbanner/'. banner_name );
// Connect to the MySQL database;
Connection = mysql_connect ();
// Select the data source guanggao to perform the query ;;
Mysql_select_db ('guanggao ',);
Query = 'select * FROM ad ';
Result = mysql_query (query );
// If the data table ad does not exist, create a new data table ad in the following structure;
If (! Result ){
Mysql_query ('
Create table ad (
Url varchar (100) not null,
Banner varchar (150) not null,
Alt varchar (100) null,
Priority tinyint (4) default 1 not null
) ') Or die (mysql_error ());
}
// Insert new data from the form into the data table ad;

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.