Mysql and php dynamic website development getting started, mysql website development _ PHP Tutorial

Source: Internet
Author: User
Tags php dynamic website
Mysql and php dynamic website development tutorial, mysql website development. Mysql and php dynamic website development tutorials. mysql website development tutorials start from forms, because forms can clearly display the interaction between databases and the web. Mysql and php dynamic website development tutorial, mysql website development

The tutorials in this series start with the form, because the form can clearly display the interaction between the database and the web. Submit a form to record registration information in the database.

This tutorial is a basic tutorial. Please skip this step. It is very popular with programmers for the stability between php and mysql. Although the hack language has recently been used to replace the php language, it is also based on php. later we can learn the hack language. It seems that there are a lot of big cows in the blog Park. I don't know if it will be sprayed, so I'm afraid ........ Of course, I have recorded the learning process by myself. The tutorial involves php and mysql, which are simple html forms. use the simplest form to understand the interaction between them. I remember that when we don't know anything or the code is unclear, we are thinking about the fantastic world of code, and it feels amazing. when we step into the world of code, we were lost again. What is the code. Here we will start with html. Of course, if html doesn't understand it, it won't come to the blog Park. Right-click the browser, and the code for viewing the source code is html. However, it is only the structure of a webpage. to form a beautiful webpage, there will certainly be a lot of things. others will have the opportunity to talk about the interaction between webpages this time. That is, the development of dynamic websites. If you do not know the form, search for it. That's the box at registration. The following is the form code.
// Here index. php is a dynamic file. I will talk about it later.

Please type your first name:

Please type your second name:

Please type your age:

This is the string of code. after the code is saved, the webpage is opened and there is only a box, and clicking is useless. of course, this is the front-end. The backend we are talking about today. What you need is to transfer the input part to the so-called database to save it, so as to facilitate website management. How do I transfer the data? Here we will talk about php and mysql. Note: when running php and mysql, an environment is required. They must have the basis for running. How can they survive. Right? Then there is a famous package. Including these environments. The next step is to install it. Address: the original address. It seems that windows 8 cannot be installed. Ah... Install it. familiarize yourself with it first. ~~ Php is in the code area Write php code in the middle. the file is in. php format and can be added to the html language. Well, put the form in. It is the same as before. Then let it become dynamic. Add several variables.

please type your first name:

please type your second name:

please type your age:

Well, familiar forms. Then you need to include the input in the variable. The php array can be used as a string array. That is, array ['name'] and name can be something you have defined. The form is very special here. this REQUEST is a super global variable and looks cool. it doesn't need to be defined, and it is always there, that is, put the form name in it, the input content is saved in this array. of course, you can also use $ _ POST ['name']. this Post is a subset of the REQUEST. In this case, they are all the same. Then your data is saved to this array, and it is very convenient to extract it. in the middle, it is used to determine whether the data is filled in, and then return the isset () is to judge whether the data is filled, and then it is the same as the html form. You have to determine whether the data is filled out. you must make a decision. The following section is available.
$error=array();if (empty($_REQUEST['first_name'])) {     echo '

you forget type your first_name;

' ;# code... $error='1';}else{ $f=$_REQUEST['first_name'];}if (empty($_REQUEST['second_name'])) { echo '

you forget type your second_name;

' ;# code... $error='2';}else{ $s=$_REQUEST['second_name'];}if (empty($_REQUEST['age'])) { echo '

you forget type your age;

'; # code... $error='3';}else{ $a=$_REQUEST['age'];}

This empty () is to judge whether it is an empty representation, and echo is the output of php. Html can also be output. Defining an error array is to determine whether there are any errors, if all are entered. OK. Then, save the variables to another variable. This looks simple. Well, then, no error is found. Then return to this section. well, this section is the most important part. it is used to connect to our database.
if (empty($error)) {     echo'

everything is ok

'; require('connect/mysqli_connect.php'); $q="insert into user (first_name,second_name,age) value('$f','$s','$a')"; $r=@mysqli_query($dbc,$q);}

The require () is the file to connect to the database. Database address, table name, user name, password, and contact the database. This file is changed. just call it to connect. It is require. This is mysqli_connect.php.
Make it as simple as possible. for a very short file, the file is saved in index. in the connect folder under the same directory of php. there is a function mysqli_connect (), which is used to connect to the database. The address names of mysqli_connect (hostname, username, password, databasename) data are generally localhost, and of course not necessarily. Check where your database is. Then there is the account, password, and database name. Then, the returned result is saved in a variable. OK, call, and then connect to the database and define another $ q. This introduces the knowledge of the database. in the database, you need to create a database and a table name, column, and then transfer the variables in the previous step one by one. Well, let's talk about the database. ~~ Ah ~~. Database management is now a lot of things like phpadmin, and it seems very convenient. There is an SQL command in that stuff. you need to enter a small command to create the stuff you just mentioned. Create a database first. The input is create database test; this creates a database. Test is the database name. It looks simple. The table name is created below. Or use create
create table user(          first_name varchar(20) not null,          second_name varchar(20) not null,          age varchar(20) not null);
Be sure to pay attention to some semicolons, colons, and commas when writing programs. Note the difference between Chinese and English; otherwise, an error occurs. Create the table name and column name. For this Dongdong varchar (20), you need to check the mysql data type. It defines what type of data it is. the column name is first defined. In this way, a user table name with three column names first_name second_name age is created. after the data is transmitted
   $q="insert into user (first_name,second_name,age) value('$f','$s','$a')";
Insert into user (,) value (,); insert en to insert the data. One by one corresponds to the column name followed by its value. Isn't the variable just saved? well. The input stuff goes in.
This function is also important. The connection before mysqli_query () is followed by the query parameter. In this way, the connection is established. Doon, Doon, and ~~~ It is running .. Enter something to the form. Then click submit, and refresh the database to see if the column name is missing. all the code is the main index. php This is a test

'; $ Error = array (); if (empty ($ _ REQUEST ['first _ name']) {echo'

You forget type your first_name;

'; # Code... $ error = '1';} else {$ f = $ _ REQUEST ['first _ name'];} if (empty ($ _ REQUEST ['second _ name']) {echo'

You forget type your second_name;

'; # Code... $ error = '2';} else {$ s = $ _ REQUEST ['second _ name'];} if (empty ($ _ REQUEST ['age']) {echo'

You forget type your age;

'; # Code... $ error = '3';} else {$ a = $ _ REQUEST ['age'];} if (empty ($ error) {echo'

Everything is OK

'; # Code... require ('connect/mysqli_connect.php '); $ q = "insert into user (first_name, second_name, age) value (' $ f', '$ S',' $ ') "; $ r = @ mysqli_query ($ dbc, $ q) ;}?>View Code

The mysqli_connect.php file under connect in the same directory.

Which is

View Code

There should also be a header.html file in the same directory's uplodes folder. That's all you need.

Well, the interaction is formed. There are still many things that are not added. today is simple. That's it. There are also error reports and other things. The form will gradually improve all functions. Well, that's good. there will be a lot to do later. Well, let's talk about it later. Reference: larry Ullman PHP and MySQL for Dynamic Web Sites visual quickPro Guide foruth Edition php and mysql Dynamic Website Development

PHP + MySQL + Dreamweaver 8 dynamic website development from foundation to practice news and publishing system background management password?

You have a try. the username and password are both admin. your login. php code will be uploaded to help you find it?

Error message

Http:// and php dynamic website development introductory tutorial, mysql website development this series of tutorials by the form of the beginning to write, because the form can be the database and web interaction between the performance is very obvious. Mention...

Related Article

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: 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.