PHP 5 sample code for managing any database table of MySQL 5 (2) _ PHP Tutorial

Source: Internet
Author: User
PHP 5 manages any database table in MySQL 5 (2 ). Continued: click add to jump to add. php (as the mainstream development language) add. php (as the mainstream development language) htmlheadtitleAddanentrytothedatabaseti resume: click add an entry to jump to add. php (as the mainstream development language)
// Add. php (as the mainstream development language)

Add an entry to the database



Add an entry
$ Database = "sunsite ";
$ Tablename = $ _ GET [tablename];
MySQL (best combination with PHP) _ connect ("localhost", "root", "") or die ("Problem connecting to DataBase ");
$ Query = "show columns from $ tablename ";
$ Result = MySQL (the best combination with PHP) _ db_query ($ database, $ query );
$ Column = 0;
If ($ result)
{
While ($ r = MySQL (the best combination with PHP) _ fetch_array ($ result ))
{
$ Colname [$ column] = $ r [0];
$ Column = $ column + 1;
}
MySQL (the best combination with PHP) _ free_result ($ result );
}
$ Id = 0;
Do
{
$ Id ++;
$ Query = "select * from $ tablename where $ colname [0] = $ id ";
$ Result = MySQL (the best combination with PHP) _ db_query ($ database, $ query );
}
While (MySQL (best combination with PHP) _ fetch_array ($ result ))
?>

(As the mainstream development language )? Tablename = "> Finish

IDs are automatically searched and generated, and they must be unique in the database. After you click add, the content will be written to the database. then, you will be asked to add the content until you finish adding the content and click finish to return to the previous layer. the database content after the added entry is displayed.
Below is the addsoftware. php (as the mainstream development language) for database operations during the addition process)
// Addsoftware. php (as the mainstream development language)
$ Database = "sunsite ";
$ Tablename = $ _ POST [tablename];
MySQL (best combination with PHP) _ connect ("localhost", "root", "") or die ("Problem connecting to DataBase ");
$ Query = "show columns from $ tablename ";
$ Result = MySQL (the best combination with PHP) _ db_query ($ database, $ query );
$ Column = 0;
If ($ result)
{
While ($ r = MySQL (the best combination with PHP) _ fetch_array ($ result ))
{
$ Colname [$ column] = $ r [0];
$ Column = $ column + 1;
}
MySQL (the best combination with PHP) _ free_result ($ result );
}

For ($ col = 0; $ col <$ column; $ col ++)
$ Para [$ col] =_ _ POST [$ colname [$ col];

If ($ _ POST [name])
{
MySQL (best combination with PHP) _ connect ("localhost", "root", "") or die ("Problem connecting to DataBase ");
$ Query = "insert into $ tablename values ($ para [0]";
For ($ col = 1; $ col <$ column; $ col ++)
$ Query = $ query. ",". $ para [$ col]. "";
$ Query = $ query .");";

$ Result = MySQL (the best combination with PHP) _ db_query ($ database, $ query );
Header ("Location: add. php (as the mainstream development language )? Tablename = $ tablename ");
}
Else
{
Echo "No name Entered. Please go back and reenter name ";
}
?>

To be continued.

Compile (as the current mainstream development language) // add. php (as the current mainstream development language) html headtitleAdd an entry to the database/ti...

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.