After php gets the value, two dots must be added before it can be inserted into the database? ?
过客
过客 2019-02-01 10:55:16
0
5
1939
<?php
//表单获取值后,插入到数据库语句两边需要加 点 。才可以插入数据库中。
//反之则为什么不行?  这是涉及哪一块知识?
/*问题事例:
sql2 = "INSERT INTO test2(标题,留言) 
VALUES('".$title."','".$content."')";  */
//连接数据库、
$conn = mysqli_connect('localhost','root','123456','demo');
if(mysqli_connect_errno($conn)){
	die('连接mysql失败'.mysqli_connect_error($conn));
}
else{
	echo '<h3>mysql连接成功</h3>';	
}
$sql='CREATE TABLE test2(
id int(10) primary key auto_increment,
标题 char(20) NOT NULL,
留言 text NOT NULL);';
if(mysqli_query($conn,$sql)){
	
	echo '表创建成功';
}else{
	echo '表创建失败';
}
//获取输入值
$title = $_POST['title'];
$content = $_POST['content'];

$sql2 = "INSERT INTO test2(标题,留言) 
VALUES('".$title."','".$content."')";

if (mysqli_query($conn, $sql2)) {
 echo '插入成功';
} else {
 echo '插入失败';
}
mysqli_close($conn);
?>


过客
过客

reply all(3)
航航

Firstly, mysql requires quotation marks when inserting Chinese characters. Secondly, php dots are used to connect characters

从入门到删库跑路

You don’t need to add any dots, you can wrap it with {}

乔xx

. Just a connector. . If you write this without the dot '', the content will not be parsed and remain as is

  • reply PHP double quotes can directly parse variables. When operating a database, I just add two more dots like that.
    过客 author 2019-02-03 09:40:41
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template