Home > Article > Backend Development > PHP system summary sharing
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:
mysqli_query($con,'set names utf8');$insertsql = "update test4 set fname='$fname',words='$words' where id='{$_SESSION['id']}'";if(mysqli_query($con,$insertsql)){ echo "感谢您的参与!<br/>Copyright@2016 Apple Inc."; }else{ echo "<a href='p3.php'>信息入录失败,点此返回</a>"; }
这里 where id='{$_SESSION['id']}' 若直接写成where id='$_SESSION['id']' php会出现错误
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
这里还有一个主要点:mysqli_query($con,'set names utf8'); 之前写php关于mysql的代码,最后将信息入录数据库,数据库保存的信息一直是乱码。 而且我的php文档格式 和 头标题 和数据库设置都是utf-8。很不解。 这次,将数据库中的所有的text格式改成了varchar()格式,并且在php使用mysql语句之前加上了mysqli_query($con,'set names utf8'); 这样一行代码,最后终于成功了!!!没有出现乱码。
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:
echo "<script herf='p1.php'> alert('弹窗文字显示');window.location.href='需要跳转的网页网址';</script>";
4. Use html code to automatically jump to the web page function
<html> <script type="text/javascript"> <!-- function redirect() { window.location.href='(将要跳转的网页网址)p4.php#mybottom'; } window.setTimeout(redirect,1000); //--> </script></html>然后还需要在将要跳转的网页加一行代码:<a name="mybottom"></a>
5. Each page must fill in complete restrictions
if(empty($_POST['age'])||empty($_POST['gender'])||empty($_POST['bg'])||empty($_POST['group'])){ echo "<script herf='p1.php'> alert('请将信息填写完整');window.location.href='p1.php';</script>"; }; 这里我使用了empty语句,结合逻辑语句,再加上弹窗,实现信息填写完整限制条件和弹窗提醒返回原网页。
6. Drop-down menu, and post transmission to another web page to accept drop-down menu information
开始时,我的代码是这样的,结果一直无法接受<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['gender'];
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:
mysqli_query($con,'set names utf8');$insertsql = "update test4 set fname='$fname',words='$words' where id='{$_SESSION['id']}'";if(mysqli_query($con,$insertsql)){ echo "感谢您的参与!<br/>Copyright@2016 Apple Inc."; }else{ echo "<a href='p3.php'>信息入录失败,点此返回</a>"; }
这里 where id='{$_SESSION['id']}' 若直接写成where id='$_SESSION['id']' php会出现错误
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
这里还有一个主要点:mysqli_query($con,'set names utf8'); 之前写php关于mysql的代码,最后将信息入录数据库,数据库保存的信息一直是乱码。 而且我的php文档格式 和 头标题 和数据库设置都是utf-8。很不解。 这次,将数据库中的所有的text格式改成了varchar()格式,并且在php使用mysql语句之前加上了mysqli_query($con,'set names utf8'); 这样一行代码,最后终于成功了!!!没有出现乱码。
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:
echo "<script herf='p1.php'> alert('弹窗文字显示');window.location.href='需要跳转的网页网址';</script>";
4. Use html code to automatically jump to the web page function
<html> <script type="text/javascript"> <!-- function redirect() { window.location.href='(将要跳转的网页网址)p4.php#mybottom'; } window.setTimeout(redirect,1000); //--> </script></html>然后还需要在将要跳转的网页加一行代码:<a name="mybottom"></a>
5. Each page must fill in complete restrictions
if(empty($_POST['age'])||empty($_POST['gender'])||empty($_POST['bg'])||empty($_POST['group'])){ echo "<script herf='p1.php'> alert('请将信息填写完整');window.location.href='p1.php';</script>"; }; 这里我使用了empty语句,结合逻辑语句,再加上弹窗,实现信息填写完整限制条件和弹窗提醒返回原网页。
6. Drop-down menu, and post transmission to another web page to accept drop-down menu information
开始时,我的代码是这样的,结果一直无法接受<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['gender'];
第一次接一个真正的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!