HTML and PHP, MySQL interaction
Why use the database?
World Wide Web (WWW) is more than just a place to provide information. If you have anything, make a website, you can also share with people around the world. However, this is not a very easy thing. When the website is more, you may encounter such problems:
The website contains too many things, making visitors can't get what they want very quickly. This issue is fatal for a website to some extent.
Visitors want to provide you with information, and this information must be saved for later use.
The above two questions can be solved by the database!
In the world of WWW, the database is everywhere. As Yahoo! Amazon, eBay, small to a simple message board, you can see the use of the database. It can even be said that the database is the foundation of all advanced applications.
Why do I know with PHP and MySQL, almost all major commercial website databases are based on SQL. The most popular may have Oracle. It is very powerful, of course, it is also expensive. SQL is not an application, but a language, it is a short written for Structure Query Language, which is used to operate and query the database.
In the last few years, some companies have developed SQL applications of "Open Code", where the most famous may be Mysql. It is not just free, for a general small and medium database application, its performance is not inferior to Oracle.
To run mysql on a website, you need a scripting language to interact with the database. In the past, Perl is the most popular. But now it seems that PHP seems to be more excellent. Don't ask me what is there? ? In the past, I used Perl, it works very well, but now everyone likes to use PHP. Its popularity has its truth.
Let's take a look at how PHP works. Take a look at this code below:
PHP
Print "Hello, World."
? >
body>
html>
When requesting this page, it will display "Hello, World" in the browser.
It can be seen that the PHP script is embedded in the HTML file. It ends with "" To end with "?>". Not only that, we can even embed the HTML tag in the PHP script:
PHP
Print "";
Print "
";Print "Hello, World."
Print " body>";
Print " html>";
? >
The two methods are the same, the effect is the same. But in some special cases, one of them is more convenient.
PHP's Prints statement
The simplest interaction of PHP and HTML is implemented by a Print statement:
PHP
Print "Hello, World.";? >
Print is the most simpler function that is also used, used to display some text in the browser window, the echo function is similar, but you can use "," to separate multiple points, this is mixing It is convenient when string constants and variables are displayed.
There is also a Printf function that formats the output of the figures. You can use a number as an integer or displayed with a scientific count.
In these functions, the use of parentheses is different:
Echo must not bring parentheses Printf but must have prints that can be available without displaying a string or a number is simple, just follow the variable name or constant followed behind the print statement. However, if you want to display an array, is it written like this:
Print $ myarray;
The result of its output will be "array", PHP tells you $ myArray is an array. This will have some use when you don't have a variable is an array, but now we want to see the contents of the array.
You can use the ImpLode function to convert an array into a string. It contains two parameters, the first is the array variable name, the second is the separator of the array content. When the conversion is completed, the content of the array is linked by the separator to form a string:
$ impLodedArray = Implode ($ MyArray, ",");
Print $ IMPLODEDArray;
You can also use the Array_Walk function to implement the display of the array. This function performs the same function to perform the same function to each content of the array. E.g:
Function Printelement ($ ELEMENT)
{
Print ("$ Element
");
}
Array_walk ($ MyArray, "Printelement");
How does PHP send data to MySQL
You should have a better understanding of the HTML form. The following code is a very simple HTML form: