Tag Archives: Web
Virtual host running ASP error resolution: HTTP/1.1 New Application Failed when allowSessionState is set to false in web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<location path="Default Web Site">
<system.webServer>
<asp>
<session keepSessionIdSecure="false" />
</asp>
</system.webServer>
</location>
</configuration>
Some work, some don’t?
The resource has been blocked.
Question.
No valid summary could be found in the resource ‘http://localhost:4200/assets/css/bootstrap.min的’integrity’ attribute. css’ with computed SHA-256 integrity ‘ nvT75FkXevX06WR8vlhFFP02xzhq9qFxLQOuS0LkWyQ=’This resource is blocked.
Causes.
<!-- Bootstrap CSS -->
<!-- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous"> -->
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="assets/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
Remove:
integrity=”sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB” crossorigin=”anonymous”
"anonymous"
A cross-domain request (that is, containing the Origin:
HTTP header). But no authentication information is sent (that is, no cookies, X.509 certificates, and HTTP basic authentication information). If the server does not give the source site credentials (do not set access-control-allow-origin :
HTTP header), the image will be contaminated and restricted.
The integrity </ code>
Contains inline metadata, which is the hash value of a resource file that you get with your browser, encoded in base64 so that users can verify that a retrieved resource has not been tampered with during transmission. Check Subresource Integrity for details.
Documents:
https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/link
IntegrityError at ** NOT NULL constraint failed: learning_logs_topic.owner_id
in chapter 19 of python from introduction to practice, models add the user attribute of topic in learning_logs, that is, the topic created by the logged user, then the owner attribute of this topic is the logged user, code: Owner = model.foreignkey (User,on_delete= model.cascade), owner is the ForeignKey of User (pthon version 3.7.4, django version 2.2.6) and is coming up after makations:
, then select the option of ‘1)’, then select the user ID of 1, namely ll_admin, then the attribution user ID of the original topic is 1, namely ll_admin. The following error occurs when executing new_topic:
IntegrityError at /new_topic/ NOT NULL constraint failed: learning_logs_top.owner_id, error site as follows:
, of which topic model source code is as follows:
class Topic(models.model) :
text= model.charfield (max_length=200)
date_added= model.datetimefield (auto_now_add=True)
owner= model.foreignkey (User,on_delete= model.cascade)
def the __str__ (self) :
return self. The text p>
topicform source as follows:
class TopicForm (forms. ModelForm) :
class Meta:
model = Topic
fields = [‘ text ‘]
labels = {‘ text: “‘} p>
: new_topic under the learning_logs folder views. Py source code is as follows:
def new_topic(request) :
if request. Method! : = ‘POST’
form = TopicForm ()
the else:
form = TopicForm (request. POST).
if the form is_valid () :
form. The save ()
the return HttpResponseRedirect(‘learning_logs:topics’)
context={‘form’:form}
return render(request,’learning_logs/ new_top.html ‘,context)
this error shows null value limitation error: owner, owner is the attribute just added in models. Although the owner attribute is added in the existing topic, the newly added topic does not have an owner attribute, so an error is reported.
is solved as follows:
(1) add null=True to the models.py attribute, allowing this attribute to be empty
becomes owner= model.foreignkey after modification (User,on_delete= model.cascade, null=True). After modification, the error does not occur, but the owner of the newly added topic is null, and
is not intended by design
(2) adds the default value inside models.py.
modified owner= model.foreignkey (User,on_delete= model.cascade, default=1), and the modified error will not occur, but the owner of newly added topic is always the User with ID 1, and it is not the desired
(3) modify TopicForm and add owner field
modified TopicForm into the following:
class TopicForm (forms. ModelForm) :
class Meta:
model = Topic
fields = [‘ text, ‘the owner’]
labels = {‘ text ‘:’, ‘owner’ : ‘} p>
After
is modified, the user will select the owner of the new topic, as shown below:
although the current logged in user can choose the owner of this topic, the user can also choose other non-logged in users, which increases the risk of error
(4) in the views. Py new_topic view, get the current user with request.user and assign a value to form
is to add a line after if form.is_valid() :
form.instance.owner=request.user,
def new_topic(request) :
if request. Method! : = ‘POST’
form = TopicForm ()
the else:
form = TopicForm (request. POST).
if the form is_valid () :
form. The instance. The owner = request. User
Form. The save ()
return HttpResponseRedirect (reverse (‘ learning_logs: switchable viewer ‘))
the context = {‘ form: form}
the return render(request,’learning_logs/new_topic.html’,context)
USES the instance parameter of the Form to get the owner attribute and assigns the current user obtained by requset.user to the owner of the instance. After the modification, the program realizes the predetermined function
(5) also takes advantage of the instance parameter, but at the time of the generated Form, the modified new_topic view is as follows:
def new_topic(request) :
if request. Method! : = ‘POST’
form = TopicForm ()
the else:
form = TopicForm (request. POST)
topic = topic ()
topic. The owner = request. User
form = TopicForm (request. POST, the instance = topic).
if the form is_valid () :
form. The save ()
return HttpResponseRedirect (reverse (‘ learning_logs: switchable viewer ‘))
The context = {‘ form: form}
return render (request, ‘learning_logs/new_topic. HTML, context) p>
becomes a topic, then assign the value to the owner, and then assign the topic to the instance parameter, which costs a lot of space and time, but also achieves the predetermined function.
Solve the problem that the value in the disabled tag cannot be passed to the server
disable tag values do not pass values to the server
<input type="text" name="did" value="${dept.did}" disabled="disabled"/><br/>
solution
-
replace the field disabled in the form with readonly (if necessary, add a gray background color to the form)
<input type="text" name="did" value="${dept.did}" readonly/><br/>
li>
-
you can write a hidden attributes, one for the value of a is used to display p> li> ol>
for example: add a hidden TAB and the name and value are set to the same value as the disable tag to successfully pass the value
<input type="hidden" name="did" value="${dept.did}" > <input type="text" value="${dept.did}" disabled="disabled"/><br/>
disabled
similarity
- can make text boxes cannot be entered.
- can be modified by js script.
- want to cancel, can only delete the corresponding attribute, set flase invalid
different points
disabled
- input cannot receive focus
- using the TAB key will skip the element
- disabled will not respond to any event (e.g. the click event is invalid). The value of the disabled element
- is not committed. The
- disabled property can be used on all form elements.
readonly
- input can receive focus
- use the TAB key does not skip elements
- readonly will respond to events.
- readonly element values are submitted. The
- readonly property is only valid for type= “text”, textarea, and type= “password”.
disabled
will not be submitted to the server can’t be serialized but can be js can’t be modified on the interface all controls havedisabled
propertyreadonly
will be submitted to the server can be serialized can be js value assignment interface can’t modify all controls not necessarily havereadonly
property such asselect
drop down box
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
a project I did before was given to a college student as the graduation device. When running on her computer, I reported the following error message. The following is the complete error message:
tomcat starts the following error:
十月 04, 2018 10:14:45 下午 org.apache.catalina.core.AprLifecycleListener init
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java123\jdk1.8.0_31\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java123/bin/server;C:/Program Files/Java123/bin;C:/Program Files/Java123/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\乱七八糟的东西\好好学习天天向上\GIS开发与编程\2\supermap-iobjectsdotnet-9.0.0-15321-63946-win-zip-chs\Bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\WINDOWS\system32\config\systemprofile\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Java\jdk1.7.0_79\bin;C:\Program Files\Java\jdk1.7.0_79\jre\bin;C:\Program Files (x86)\Common Files\Autodesk Shared\;C:\Program Files\MySQL\MySQL Utilities 1.6\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Java123\jdk1.8.0_31\bin;C:\Program Files\Java\jdk1.7.0_79\jre\bin;C:\Program Files (x86)\Microsoft Visual Studio\Common\Tools\WinNT;C:\Program Files (x86)\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files (x86)\Microsoft Visual Studio\Common\Tools;C:\Program Files (x86)\Microsoft Visual Studio\VC98\bin;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;;C:\Users\30801\Desktop\eclipse;;.
十月 04, 2018 10:14:45 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:cunity' did not find a matching property.
十月 04, 2018 10:14:46 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-bio-8080"]
十月 04, 2018 10:14:46 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["ajp-bio-8009"]
十月 04, 2018 10:14:46 下午 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 1126 ms
十月 04, 2018 10:14:46 下午 org.apache.catalina.core.StandardService startInternal
信息: Starting service Catalina
十月 04, 2018 10:14:46 下午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/7.0.27
十月 04, 2018 10:14:46 下午 org.apache.catalina.util.SessionIdGenerator createSecureRandom
信息: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [229] milliseconds.
十月 04, 2018 10:14:49 下午 org.apache.catalina.core.ContainerBase startInternal
严重: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/cunity]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1128)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:782)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/cunity]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
... 6 more
Caused by: org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 15
at org.apache.tomcat.util.bcel.classfile.Constant.readConstant(Constant.java:131)
at org.apache.tomcat.util.bcel.classfile.ConstantPool.<init>(ConstantPool.java:60)
at org.apache.tomcat.util.bcel.classfile.ClassParser.readConstantPool(ClassParser.java:209)
at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:119)
at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2032)
at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1923)
at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1891)
at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1877)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1270)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:855)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:345)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5161)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
十月 04, 2018 10:14:49 下午 org.apache.catalina.core.ContainerBase startInternal
严重: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1128)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.startup.Catalina.start(Catalina.java:675)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:450)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1136)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:782)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
十月 04, 2018 10:14:49 下午 org.apache.catalina.startup.Catalina start
严重: Catalina.start:
org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.startup.Catalina.start(Catalina.java:675)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:450)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 9 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1136)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 11 more
十月 04, 2018 10:14:49 下午 org.apache.catalina.startup.Catalina start
信息: Server startup in 3828 ms
for this reason, I searched for this mistake for a whole day, also went to the Internet to look for, saw a lot of solutions on the Internet, I also summed up the following points:
1. Cache is not cleaned up by tomcat.
2. Log4j.jar package not imported.
3. Configuration in web.xml < servlet-mapping> “, not “/”.
4. No servlet-api.jar imported.
5. The version of the package is inconsistent.
none of that.
solution is: tomcat under the lib all jar is wrong, why, you follow my train of thought: click these to go to see the source code.
look at the head, is there something that says catalina.jar, right at the top of the source code. Then click in these, keep looking for, find the lib under Tomcat, you will find that you just saw the source code on the head of the jar package, is the lib under Tomcat these jar packages.
yes, that’s all make of ghost, I’ll have (tomcat7) : https://download.csdn.net/download/qq_41879385/10701965, only need to future generations in the paste, again running tomcat, to regroup, of course, you can run a success, I am looking for a day of error, so settled.
p>
Connection between PHP 7.4 and MySQL (MariaDB) under Ubuntu (kali Linux)
PHP7 or above has abolished the mysql function library, so the mysql_connect() function is no longer available. The new function libraries MySQli and PDO can completely replace this library. This article mainly introduces two kinds of library functions, PHP and mysql connection and encountered problems.
experiment, all content in ubuntu18.04.3 can also be fully run.
installation problem
PHP is connected to mysql using apache+PHP+mysql, as each part has been pre-installed in kali, see resources for details: kali installs apache, mysql, PHP. Here I want to talk about the installation need to pay attention to the problem, apache and mysql installation generally will not have problems, focus on PHP installation. After the configuration of resources is completed, create a new file index.php under /var/www. HTML folder. The content is as follows:
<?php
phpinfo();
?>
opens apache, which is enabled by default. If you are not sure, you can run the following command:
/etc/init.d/apache2 start
the following results:
the server has opened, the browser input address: http://localhost/index.php, appeared normal PHP configuration information:
page provides PHP configuration details and strong> extension module has been installed, need to emphasize the extension module!!!!!! This can cause a very common problem: the PHP information page displays normally, the static PHP page can be displayed, but the dynamic interactive page is blank! , which is often the result of PHP’s corresponding extension module not being installed. For example, the modules needed this time are MySQli and PDO (these two libraries are independent, but the two libraries are used to realize the connection between PHP and mysql respectively). However, in the latest VERSION of PHP, mySQli library will not be installed by default, which causes the mysqli functions in the PHP page will not be executed, forming a blank page.
direct command line input:
php -m
lists the extensions that have been installed:
I have now installed them. If you do not have these modules, you can install them with the following command (see reference 2 for more details) :
sudo apt-get install php7.4-mysqli //这里我的php版本是7.4.9
sudo apt-get install php7.4-PDO
at this point, all configuration is complete.
MySQL create user with authorization
Mysql can log in confidentially under
kali and default to root, while ubuntu requires a more detailed command:
mysql #kali下
--------------------------------
mysql -u root -p #kali下和ubuntu下均可,更正式
kali>
or ubuntu kali is recommended
one of the most common problems here is to report an error:
ERROR 2002 (HY000) : Can ‘t connect to local MySQL server through socket’/var/run/mysqld/mysqld. The sock ‘ strong>
there are all kinds of solution to the problem, sometimes only restart MySQL Can solve the problem: p>
systemctl restart mysql
create user
database operation commands are case sensitive.
into Mysql, the relevant user creation and authorization commands are as follows:
#drop database kali; #由于已经完成数据库的操作,数据库已经存在,这里将其删除,重新演示
show databases; #列出当前存在的数据库
create database kali; #创建数据库kali
use kail; #使用kali
#drop user 'lee'@'localhost'; #删除当前用户lee
create user 'lee'@'localhost' identified by '123'; #创建新用户,这条命令涉及PHP代码,下面详细说
select user,host,password from mysql.user; #列出所有用户、所属主机、密码(默认经过加密)
identified by ‘123’; **create user ‘lee’ @’ localhost ‘identified by’ 123 ‘;
create user ‘username’ @’ host ‘identified by’ password ‘;
username: created username;
host: specify which host the user can log in on. If it is a local user, use localhost. If you want the user to log in from any remote host, use the wildcard %;
password: the user’s login password, the password can be empty, if empty, the user can log in the server without the password;
The user information created by
is placed in mysql.user.
user authorization
authorizes the new user created. Authorization refers to the operation that the user can perform on the database, such as adding, deleting, modifying, checking, etc. The command is:
grant all privileges on kali.* to 'lee'@'localhost' identified by '123' with grant option;
flush privileges; #权限刷新
grant privileges on databasename. Tablename to ‘username’ @’ host ‘
privileges: privileges on the user, such as SELECT, INSERT, UPDATE, etc. ALL
databasename: databasename
tablename: Table name, represented by * if you want to grant the user permission to operate on all databases and tables.
for more detailed permissions, see resources 3: MySQL create users and authorizations. As a matter of fact, the connection between PHP and mysql can already be detected at this point. For a clearer representation, the contents of the database can be printed on the page. First create the content.
database content creation
basic database operation, command as follows:
show tables; #显示当前数据库下所有列表
create table users(
-> id int(10),
-> username varchar(7) ); #创建table,赋予属性
describe users; #描述表
insert into users value (1,'paradox'); #插入数据
select * from users; #显示数据
PHP7 connection mysql h2>
PHP7 has abolished the mysql library. If you want to establish PHP and mysql interaction, you can do it through mysqli and PDO library functions. This article does not elaborate on the differences and USES of mysql, MySQli and PDO. You can read Resources 4-6 for details.
PHP mysqli interacts with mysql
mysqli is object-oriented and process-oriented. Set up mysqli.php in the folder /var/www. HTML /. The content is as follows:
<?php
/*
面向对象风格,格式及参数说明:
$mysqli = new Mysqli($serve,$username,$password,$dbname);
$serve:所使用的用户主机名称,这里是本地用户localhost
$username: 数据库用户名,上面设置为lee
$password:用户对应的密码
$dbname:所使用的数据库。默认的话,会调用上一个打开的数据库
*/
$mysqli = new mysqli("localhost", "lee", "123", "kali");
if(!$mysqli) {
echo"database error";
}else{
echo"php env successful";
}
$mysqli->close();
?>
your browser input address: http://localhost/mysqli.php, the connection is successful.
PHP PDO interacts with mysql
PDOPDO’s biggest advantage over MySQLi is that PDO supports a wide variety of databases, while MySQLi only supports MySQLi. PDO’s advantages will come into play when a program wants to switch from mysql to SQL Server or Oracle in the future, because the database switch is transparent to the interface, the PHP code changes very little, and if you’re using MySQLi, you’ll have to rewrite everything you use for the database.
PDO can establish a connection in three ways: connects to the database in the form of parameters; Connect to the database through A URI; Connect to the database in the form of a configuration file. The latter two require configuration files, the first of which is used here. Similarly, under /var/www. HTML/create a file called pdo.php that reads as follows:
<?php
$dbms='mysql';
$dbName='kali';
$user='lee';
$pwd='123';
$host='localhost';
$dsn="$dbms:host=$host;dbname=$dbName";
$pdo=new PDO($dsn,$user,$pwd);
echo "PDO连接MySQL成功";
?>
, the parameter here has the same meaning, just pay attention to the format of $DSN. Enter the address http://localhost/pdo.php in the browser and the connection is successful as follows:
Of course,
can also output the contents of the database, create a file pdoo.php, the content is as follows:
<?php
header("Content-type:text/html;charset=utf-8");
$dns = 'mysql:host=localhost;dbname=kali';
$username = 'lee';
$password = '123';
try{ // PDO连接数据库若错误则会抛出一个PDOException异常
$PDO = new PDO($dns,$username,$password);
$result = $PDO->query('select * from users');
$data = $result->fetchAll(PDO::FETCH_ASSOC);
// PDO::FETCH_ASSOC表示将对应结果集中的每一行作为一个由列名索引的数组返回
print_r($data);
} catch (PDOException $error){
echo 'connect failed:'.$error->getMessage();
}
?>
your browser input: http://localhost/pdoo.php, shows the database content:
this is the front insert data in the database:
Django + jQuery get data in the form + Ajax send data
1. Method 1: obtain form data through Jquery$("# corresponding form id). SerializeArray ()
, and directly assign values to $. Ajax
data.
.serializearray () method see jQuery ajax-serializearray () method
this method puts back an array of JSON objects.
$("#postSubmit").click(function () {
let data = $("#postContent").serializeArray();
$.ajax({
url: '/decuhub/home-post-ajax',
method: 'POST',
data: data,
async: true,
success: function (result) {
console.log("post successfully!")
}
})
})
2. The method 2: by $(" # corresponding form form id) serializer () code> to obtain the form data: p>
$("#postSubmit").click(function () {
let data = $("#postContent").serializer();
$.ajax({
url: '/decuhub/home-post-ajax',
method: 'POST',
data: data,
async: true,
success: function (result) {
console.log("post successfully!")
}
})
})
. Method 3:
is not recommended
$("#postSubmit").click(function () {
let postContentForm = $("#postContent").serializeArray();
let data = {};
$.each(postContentForm, function(){
data[this.name] = this.value;
})
$.ajax({
url: '/decuhub/home-post-ajax',
method: 'POST',
data: data,
async: true,
success: function (result) {
console.log("post successfully!")
}
})
})
$.each()
reference jQuery. Each () p b>
Django's request-post
gets
<QueryDict: {'csrfmiddlewaretoken': ['vO34OFZtTj2Bp2ARMlXVJxZQb37CyuWR7ywaDC4QaJhHtcxB4xB9fnb2IOnbQ2AR'], 'content': ['asdfsd']}>
div>