MySQL and PHP dynamic website development tutorial, MySQL Web development _php Tutorial

Source: Internet
Author: User
Tags php language php and mysql php dynamic website

MySQL and PHP Dynamic Web development tutorial, MySQL Web development


This series of tutorials is written by the form, because the form can make the interaction between the database and the Web manifest. Submit the form, and the database records the registration information.

This tutorial belongs to the basic tutorial. The Great god please skip over. the robustness between PHP and MySQL is well-liked by programmers. Despite the recent emergence of hack language ready to replace the PHP language, but the language itself is based on PHP, we can learn the hack language later. It seems that the blog Park has a lot of Daniel, do not know will be sprayed, so afraid ... Of course, I am learning through the strength of their own, the process of learning is also recorded. Tutorials involve simple PHP and MySQL for HTML forms. First, the simplest form, the meaning of the interaction between the line. Remember when we do not understand anything, the code is not clear, we are thinking about the magic of the world of code, it feels fantastic, when we step into the code world, we feel at a loss. What the code is. Here, from the HTML. Of course, if the HTML is not understood, will not come to the blog park. Casually say is the browser right-click, the source code to view the code is HTML. But it is only the structure of the Web page, to form a beautiful page of course, a lot of things, others have the opportunity to say, this time the interaction between the Web. This is the development of dynamic Web sites. If you don't know the form, search for it. It was the time of the registration, those boxes. here is the form code.
<formAction= ' index.php 'Method= ' Post '>//The index.php here is a dynamically transmitted file. It will be said later. <P>Please type your first name:<inputtype= "text"name= "First_Name"value=""> 
     P > < P >Please type your second name:<input  type= "text"  name  = "Second_name"  value= "" " > 
      P>  <p>Please type your age:<input  type= " Text "  name=" Age "  value=" "> 
       p>  <p><input  type= "Submit"  Name= ' Submit '  value= ' register '> 
        P>  
         form>     
This is the string of code, after saving, the Web page opens, only the frame, click No use, of course, this is the front end. The back end of what we say today. All you need to do is transfer the input to the so-called database and save it so that it's easy to manage. How is it going to pass through? This is about PHP and MySQL. Note: When running PHP and MySQL, it is necessary to have the environment. To have the basis for their operation. Their environment, otherwise how to survive it. Right? Then there is a well-known package of packages. These environments are included. The next step is to install the line. Address: http://apmserv.s135.com/respect the original address. looks like Windows 8 doesn't fit. Hey... install well, first familiar with it. En ~ ~ PHP is in the code area in the middle of writing PHP code, file. php format, which can be added to the HTML language. Well, put the forms in. put it in. Access it is the same as the original. Then let it become dynamic. Add a few variables.
<P>Please type your first name:<inputtype= "text"name= "First_Name"value="
 
    ">
   P><P>Please type your second name:<inputtype= "text"name= "Second_name"value="
 
     " > 
      P > < P >Your Age:<input  type= "text"  name= "Age"  value= " 
       "> 
       P><P  ><input  type= "Submit"  name= ' Submit '  value= ' register '> 
        P>   
well, very familiar with the form. Then you have to put the input into that variable inside. Here is the PHP array, the PHP array can be used in the form of a string array. is array[' name ') and then name can be something you define. Here for the form is very special, this request is a super-global variable, as if it is cool, it is not defined, it has been, is the name of the form in the inside, the input The content is stored in this array, of course, can also use $_post[' name '] This POST is a subset of the request. Anyway, that means the same thing. then your data is saved in this array, and then it is convenient to extract it, the middle of the use of the decision to fill in the data, and then return, this isset () is to determine whether to fill in the data, and then the same as the HTML form. You have to decide whether the data is filled out, always have a judgment. there's the following paragraph.
$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 the judgment is not empty expression, echo is the output of PHP. You can also output HTML as well. Define an error array is to judge if there are any errors, if they are filled in. It's OK. then save those variables in another variable. This looks simple. Well, then, found no errors. and then return to this paragraph, well, this paragraph is the most important part, is to rely on it to connect our database.
if (Empty ($error)) {     echo'

Everything is OK

' ; Require ('connect/mysqli_connect.php'); $q="insertintouser (first_name,second_name,age) value (' $f','$s','$a' )"; $r=@mysqli_query($DBC, $q);}

the Require () is the file that needs to connect to the database. Database address Ah, table name Ah, user name Ah, password Ah, rely on these contact database. the file is in a different place. Just call it over and connect. It's require. this is the mysqli_connect.php.
  
    $dbc=@mysqli_connect(localhost,root,123,test);? >
as simple as possible, haha. short file, this file is stored in the index.php in the same directory of the Connect folder inside. There is a function mysqli_connect () This function is connected to the database. Mysqli_connect (hostname,username,password,databasename) the address name of the data is usually localhost, and certainly not necessarily. See where your database is. Then there is the account, password, database name. It then returns the saved in a variable. OK, and then it's connected to the database. The following also defines a $q, which is also the knowledge of the database, in the database, you want to create a database Ah, table name Ah, column Ah, and then one by one matching the variables just passed. Well, this is about the database. Yes ~ ~ ~ ~. database Management Now a lot of phpadmin and the like, it seems very convenient appearance. In that east, there is a SQL command place, you have to enter a small command, create just said those things. Let 's start by creating a database. Entered is the CREATE database test; this creates a database. Test is the name of the database. It's a simple look. here's how to create a table name. or create?
Create Table User (          varchar(notnull,          varchar(  notnull,          varchar(notnull) );
write the program must pay attention to some semicolon ah, colon ah, comma ah and so on. Notice where, how to use, the Chinese and English version of the semicolon difference, otherwise it is wrong. This is the creation table name and the column name. this East varchar (20) You will have to look up the MySQL data type. is to define what type of data it is, and the first is the column name. this creates a user table name of three column names First_Name second_name age; all right, data transfer past.
   $q="insertintouser (first_name,second_name,age) value ('$f ','$s','$a');
This is it, insert into user ( ,,,,) value (,,,,,); insert en insert these data into. One by one corresponds to the previous column name is the value of it. Isn't that the variable you just saved, huh? The input of the dongdong went in.
$r=@mysqli_query($DBC, $q);
This function is also important. Mysqli_query () is in front of the connection, and the following parameter is the query itself. so it's connected. Knock Knock ~ ~ ~ run up. you enter something into the form. Then click Submit, and then refresh the database is not found the column name more things all the code is the following main index.php include (' includes/header.html ');Echo'

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', '$a')"; $r=@mysqli_query($dbc,$q);}? >View Code

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

Inside is

$dbc =@mysqli_connect(localhost,root,123,test);? >View Code

There should also be a header.html file under the includes folder in the same directory. That's all right.

Well, so the interaction is formed. There are a lot of things not to add, today simple point. That's it. and a bug report and stuff like that. After the form has gradually perfected all functions. yes, that's good.There's a lot of work to do behind it. Well, I'll talk about it later. References:Larry Ullman PHP and MySQL for the Dynamic Web Sites Visual Quickpro guide Foruth Edition"PHP and MySQL Dynamic web development"

"Php+mysql+dreamweaver 8 dynamic website development from Foundation to practice" news release system admin password?

You try, the user name and password are admin, your that login.php code sent up let me help you find?

Error hints


http://www.bkjia.com/PHPjc/834766.html www.bkjia.com true http://www.bkjia.com/PHPjc/834766.html techarticle MySQL and PHP Dynamic Web development tutorial, MySQL Web Development This series of tutorials is written by the form, because the form can make the interaction between the database and the Web very obvious. To 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: 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.