Home Backend Development PHP Tutorial PHP system summary sharing

PHP system summary sharing

Mar 31, 2018 pm 03:55 PM
php share Summarize

This article mainly shares with you the relevant knowledge of PHP system summary, hoping to help everyone.

1. About session
session_start();
$_SESSION['id']=time();//Use session to fill in the questionnaire for each person Users have a randomly assigned ID so that their data updates can be stored in the database.

After that, for each web page that needs to use $_SESSION['id'], you must first add
session_start();

and then use the mysqli_query language to operate the database.
You need to pay attention to the update operation code here:

1

2

3

mysqli_query($con,&#39;set names utf8&#39;);$insertsql = "update test4 set fname=&#39;$fname&#39;,words=&#39;$words&#39; where id=&#39;{$_SESSION[&#39;id&#39;]}&#39;";if(mysqli_query($con,$insertsql)){    echo "感谢您的参与!<br/>Copyright@2016 Apple Inc.";

}else{    echo "<a href=&#39;p3.php&#39;>信息入录失败,点此返回</a>";

}

Copy after login
Copy after login

1

这里 where id=&#39;{$_SESSION[&#39;id&#39;]}&#39; 若直接写成where id=&#39;$_SESSION[&#39;id&#39;]&#39; php会出现错误

Copy after login
Copy after login

Because quotation marks cannot appear continuously in a string, otherwise it will be truncated. So the correct code uses a square bracket {} to enclose the middle quotation marks. I have never written this correctly before, which resulted in me being unable to use the session.

2. About Chinese information encoding format

1

2

3

4

5

这里还有一个主要点:mysqli_query($con,&#39;set names utf8&#39;);

之前写php关于mysql的代码,最后将信息入录数据库,数据库保存的信息一直是乱码。

而且我的php文档格式 和 头标题 和数据库设置都是utf-8。很不解。

这次,将数据库中的所有的text格式改成了varchar()格式,并且在php使用mysql语句之前加上了mysqli_query($con,&#39;set names utf8&#39;);

这样一行代码,最后终于成功了!!!没有出现乱码。

Copy after login
Copy after login

So, in the future, everyone must pay attention to 4 points when using the database to enter Chinese information:
(1 ) PHP document format utf-8
(2) Header title utf-8
(3) Database varchar() format setting utf-8
(4) Add mysqli_query($con, 'set names utf8');

The code of the pop-up window in 3.php
It was originally a very simple line of code, but the search on the Internet was wrong. I think maybe every The formats written by individuals are different, and the applicable PHP versions are also different. As a result, the pop-up window cannot be displayed correctly every time I use other people's code. Finally, I got the answer through the knowledge gained from asking friends and searching. The code is as follows:

1

echo "<script herf=&#39;p1.php&#39;> alert(&#39;弹窗文字显示&#39;);window.location.href=&#39;需要跳转的网页网址&#39;;</script>";

Copy after login
Copy after login

4. Use html code to automatically jump to the web page function

1

2

3

4

5

6

7

8

<html>

    <script type="text/javascript">

        <!--        function redirect()

        {

        window.location.href=&#39;(将要跳转的网页网址)p4.php#mybottom&#39;;

        }

        window.setTimeout(redirect,1000);        //-->

    </script></html>然后还需要在将要跳转的网页加一行代码:<a name="mybottom"></a>

Copy after login
Copy after login

5. Each page must fill in complete restrictions

1

2

3

if(empty($_POST[&#39;age&#39;])||empty($_POST[&#39;gender&#39;])||empty($_POST[&#39;bg&#39;])||empty($_POST[&#39;group&#39;])){       echo "<script herf=&#39;p1.php&#39;> alert(&#39;请将信息填写完整&#39;);window.location.href=&#39;p1.php&#39;;</script>";

    };

这里我使用了empty语句,结合逻辑语句,再加上弹窗,实现信息填写完整限制条件和弹窗提醒返回原网页。

Copy after login
Copy after login

6. Drop-down menu, and post transmission to another web page to accept drop-down menu information

1

2

3

4

5

6

7

8

9

10

11

12

13

开始时,我的代码是这样的,结果一直无法接受<form action="p1.handle.php" method="post">

            <label>(2)性别:</label>

            <select>

            <option value="女">女</option>

            <option value="男">男</option>

            </select>后来调整代码如下:<form action="p1.handle.php" method="post">

            <label>(2)性别:</label>

            <select name="gender">

            <option value="女">女</option>

            <option value="男">男</option>

            </select>改进的一点就是:<select name="gender">为表情附上识别名字name="gender"

然后在另一个网页(p1.handle.php)就可以接收了

$gender = $_POST[&#39;gender&#39;];

Copy after login
Copy after login

The first time to take on a real php project, I'm very excited, but really tired
I remember the first time I used PHP to write a student management system, there were several places that were wrong no matter how I modified them, and I still couldn't find the answer after searching Baidu. I have been troubled for a long time. This time the questionnaire system has modified the problems of the last student management system and implemented some new functions.
The summary has not been finished yet and will be updated in the near future. It was just handed over to the demander today, and the demander pointed out several points for improvement. I'll make more changes.
This time when I took on the project, I really found that my foundation was not strong. There are many codes that I only know roughly, but I am completely ignorant about the details. The result is that I may have to think about a very simple line of code for several hours, resulting in very low efficiency. I hope these details can be resolved by doing more projects and asking more questions. Another thing I want to say is that sometimes people forget how to write code and search Baidu, but often they can’t find the results they want (or the code is invalid). This may be due to the format of each person’s code and the version of the language they use. Different people cause these mistakes, so if there are masters around you, try to ask the masters around you for advice!

1. About session
session_start();
$_SESSION['id']=time();//Use session to fill in the questionnaire for each person Users have a randomly assigned ID so that their data updates can be stored in the database.

After that, for each web page that needs to use $_SESSION['id'], you must first add
session_start();

and then use the mysqli_query language to operate the database.
You need to pay attention to the update operation code here:

1

2

3

mysqli_query($con,&#39;set names utf8&#39;);$insertsql = "update test4 set fname=&#39;$fname&#39;,words=&#39;$words&#39; where id=&#39;{$_SESSION[&#39;id&#39;]}&#39;";if(mysqli_query($con,$insertsql)){    echo "感谢您的参与!<br/>Copyright@2016 Apple Inc.";

}else{    echo "<a href=&#39;p3.php&#39;>信息入录失败,点此返回</a>";

}

Copy after login
Copy after login

1

这里 where id=&#39;{$_SESSION[&#39;id&#39;]}&#39; 若直接写成where id=&#39;$_SESSION[&#39;id&#39;]&#39; php会出现错误

Copy after login
Copy after login

Because quotation marks cannot appear continuously in a string, otherwise it will be truncated. So the correct code uses a square bracket {} to enclose the middle quotation marks. I have never written this correctly before, which resulted in me being unable to use the session.

2. About Chinese information encoding format

1

2

3

4

5

这里还有一个主要点:mysqli_query($con,&#39;set names utf8&#39;);

之前写php关于mysql的代码,最后将信息入录数据库,数据库保存的信息一直是乱码。

而且我的php文档格式 和 头标题 和数据库设置都是utf-8。很不解。

这次,将数据库中的所有的text格式改成了varchar()格式,并且在php使用mysql语句之前加上了mysqli_query($con,&#39;set names utf8&#39;);

这样一行代码,最后终于成功了!!!没有出现乱码。

Copy after login
Copy after login

So, in the future, everyone must pay attention to 4 points when using the database to enter Chinese information:
(1 ) PHP document format utf-8
(2) Header title utf-8
(3) Database varchar() format setting utf-8
(4) Add mysqli_query($con, 'set names utf8');

The code of the pop-up window in 3.php
It was originally a very simple line of code, but the search on the Internet was wrong. I think maybe every The formats written by individuals are different, and the applicable PHP versions are also different. As a result, the pop-up window cannot be displayed correctly every time I use other people's code. Finally, I got the answer through the knowledge gained from asking friends and searching. The code is as follows:

1

echo "<script herf=&#39;p1.php&#39;> alert(&#39;弹窗文字显示&#39;);window.location.href=&#39;需要跳转的网页网址&#39;;</script>";

Copy after login
Copy after login

4. Use html code to automatically jump to the web page function

1

2

3

4

5

6

7

8

<html>

    <script type="text/javascript">

        <!--        function redirect()

        {

        window.location.href=&#39;(将要跳转的网页网址)p4.php#mybottom&#39;;

        }

        window.setTimeout(redirect,1000);        //-->

    </script></html>然后还需要在将要跳转的网页加一行代码:<a name="mybottom"></a>

Copy after login
Copy after login

5. Each page must fill in complete restrictions

1

2

3

if(empty($_POST[&#39;age&#39;])||empty($_POST[&#39;gender&#39;])||empty($_POST[&#39;bg&#39;])||empty($_POST[&#39;group&#39;])){       echo "<script herf=&#39;p1.php&#39;> alert(&#39;请将信息填写完整&#39;);window.location.href=&#39;p1.php&#39;;</script>";

    };

这里我使用了empty语句,结合逻辑语句,再加上弹窗,实现信息填写完整限制条件和弹窗提醒返回原网页。

Copy after login
Copy after login

6. Drop-down menu, and post transmission to another web page to accept drop-down menu information

1

2

3

4

5

6

7

8

9

10

11

12

13

开始时,我的代码是这样的,结果一直无法接受<form action="p1.handle.php" method="post">

            <label>(2)性别:</label>

            <select>

            <option value="女">女</option>

            <option value="男">男</option>

            </select>后来调整代码如下:<form action="p1.handle.php" method="post">

            <label>(2)性别:</label>

            <select name="gender">

            <option value="女">女</option>

            <option value="男">男</option>

            </select>改进的一点就是:<select name="gender">为表情附上识别名字name="gender"

然后在另一个网页(p1.handle.php)就可以接收了

$gender = $_POST[&#39;gender&#39;];

Copy after login
Copy after login

第一次接一个真正的php项目,很激动,不过确实累啊
记得第一次用php写学生管理系统的时候,有好几个地方怎么修改都不对,搜百度也依旧没有答案。苦恼了很久。这次的问卷调查系统修改了上次学生管理系统的问题,并新实现了一些功能。
总结还没写完近期将持续更新,今天刚交给需求方,需求方又指出几点要改进的地方。我再做修改。
这次接项目也是真的发现自己的基础不牢啊。有多的代码只是大概知道,而对于细节方面简直小白,造成的结果是,一行很简单的代码,我可能要想几个小时,造成效率很低。这些细节希望通过多做项目,多问问题得到解决。还想说一个就是,大家有时候忘了代码怎么写就去搜百度,但是经常搜不到自己想要的结果(或者说代码无效),这可能就是每个人写代码的格式以及使用语言的版本不同造成这些错误的,所以,若周围有大神,还是尽量向身边的大神请教吧!

相关推荐:

php系统函数的实例详解

The above is the detailed content of PHP system summary sharing. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1670
14
PHP Tutorial
1274
29
C# Tutorial
1256
24
PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

See all articles