1024programmer PHP [Original] How did I teach my female classmates to develop PHP from scratch (3)

[Original] How did I teach my female classmates to develop PHP from scratch (3)

After reading a lot of comments, they all said that there is no truth without pictures, and the high-definition and uncensored pictures were promised. In order to respond to many calls, and with the consent of the girl, I will post a picture today. Bar. Don’t be disappointed yet, and don’t say I’m a liar. Looking at the chat content, it is actually easy to make a girl happy. When teaching her to learn something, give her a sense of accomplishment and make her feel that she has really learned

I read a lot of comments, and they all said “No pictures, no truth”, “The promised high-definition and uncensored big pictures”. In order to respond to many calls, with the consent of the girl, I will post one today. Take a picture.

Don’t be disappointed yet, and don’t say I’m a liar. Looking at the chat content, it is actually easy to make a girl happy. When teaching her to learn something, give her a sense of accomplishment and make her feel that she has really learned something and made progress. Then she will naturally be elated and feel that the time has passed. Come on, I feel good staying with you. If you say all day long, “You are too stupid, you don’t understand this”, or if you say, “You can’t teach me anything, I’ll write it for you and then you can fool the teacher”, other girls will be happy What? When you help people, you need to help them with ideas. As long as you put 100% of the programmers’ efforts into thinking about the code into the girl, she will not always be issued a good person card or help someone repair their computer late at night and ride a bicycle to go home. .

——————————————————End of chat——————————————————

Previous review: In Part (2), we focused on form submission, obtaining and processing the data of the submitted form. At the end, it also mentioned the content of PHP operating MySQL and demonstrated how to connect to the database.

So today, what we are going to explain is mainly the following two points: 1. How to simply interact with the database 2. Simple MVC architecture

Step 6: Get data from the database

Generally speaking, during the login process, we only need to fetch data from the database and compare it with the data extracted from the page – to verify the user name, password and permissions, without adding, deleting or modifying. So, here we take the query operation as an example, and for other operations, let the girl read a book, and don’t let her become a hand-in-hand.

First, let’s take a look at the basic tables of the database I built in advance. There is no sql statement provided here. Let her build it by herself. With the help of the graphical interface, it is quite simple.

After reading the basic table, look at the PHP code part – Controller.php

 1 <?php
  2 session_start();
  3
  4 $user_id =$_POST['user_id'];
  5 $user_password= $_POST['user_password'];
  6 $user_limitation=$_POST['limit'];
  7
  8 $host ='localhost';
  9 $user_name='root';
 10 $password ='';
 11
 12 $admin_limitation ='1';
 13 $guest_limitation='0';
 14
 15 $conn = mysql_connect($host,$user_name,  $password);//Connect to MySQL
 16 if(!$conn){
 17 die('Database connection failed:'.mysql_error());
 18  }
 19 mysql_select_db('scut_xiaoy');//Select database
 20
 21 $sql='select id,password,limitation from login';//Define sql statement
 22
 23 $result = mysql_query($sql) OR die("
ERROR:
".mysql_error()."
The SQL that caused the problem: ".$sql); 24 //Execute the sql statement. If successful, the result set will be returned and assigned to the variable $result. If failed, the die statement will be executed. 25The ogin method processes data (verifies accounts) and returns a judgment value, and finally jumps to different pages based on different return values. This is the role of the Controller during the login process - to receive the data (user name, password, etc.) from the view, then transfer the data to the Model for processing, and finally select different Views based on the return value. ) to jump (in fact, the data returned by the model can also be handed over to the view for display through the controller, let’s not mention it for now).

If you understand the Controller, the Model is also easy to understand. Please see the code of Model.php——

 1 <?php
  2 class Class_Login{//Definition of Class_Login class
  3 public function login($user_id,$user_password, $  user_limitation){//Define login method
  4 $host ='localhost';
  5 $user_name='root';
  6 $password ='';
  7
  8 $admin_limitation ='1';
  9 $guest_limitation='0';
 10
 11 $conn = mysql_connect($host,$user_name,  $password);//Connect to MySQL
 12 if(!$conn){
 13 die('Database connection failed:'.mysql_error());
 14  }
 15
 16 mysql_select_db('scut_xiaoy');//Select database
 17 $sql='select id,password,limitation from login';
 18 $result = mysql_query($sql) OR die  ("
ERROR:
".mysql_error()."
The SQL that caused the problem: ".$sql); 19 20 if($num=mysql_num_rows($result)) 21 { 22 echo '
' ;
 23 while($row=mysql_fetch_array($result,  MYSQL_ASSOC)){
 24 if($row['id']==$user_id&&  $row['password']==$user_password&&$row['limitation']==$user_limitation){
 25 if($row['limitation']==$guest_limitation)  {
 26 return 0;
 27  }
 28 else{
 29 return 1;
 30  }
 31  }
 32  }
 33  }
 34 mysql_close($conn);
 35  }
 36  }
 37
 38 ?>

As for the two Views, that is, user.html and admin.html, I won’t post them. Everyone knows the reason~

For a while, she probably won’t quite understand the meaning of this, but she will slowly understand it later in the project.

——————————————————————Don’t laugh, this is the dividing line———————————— ————————

I have been blogging for several days, and I feel like my gains are getting bigger and bigger. Thank you to all my friends who follow this series of blogs intentionally or unintentionally. Without your views and comments, I would never be able to write these words as passionately as I do now. In addition, I am very pleased that the girl is very interested in learning and often tells me that time flies very fast. In fact, the girl has no plans to take a technical route in the future. After completing the practical training tasks prescribed by the school, she will devote herself to preparing for the postgraduate entrance examination. So, she was able to get to this point, and as a "technical consultant" I really don't have much more to say.

Let me tell you something, my sister is in her senior year in Beijing, and I am in Guangzhou, so far away from each other, so everyone, ahem, understands. Finally, I would like to disclose that I have obtained a profile photo of her and am considering whether to expose it.

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/original-how-did-i-teach-my-female-classmates-to-develop-php-from-scratch-3-4/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索