search

Home  >  Q&A  >  body text

After php gets the value, two dots must be added before it can be inserted into the database? ?

<?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);
?>


过客过客2156 days ago1940

reply all(5)I'll reply

  • 航航

    航航2019-02-14 11:06:55

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

    reply
    1
  • 从入门到删库跑路

    从入门到删库跑路2019-02-01 16:54:13

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

    reply
    0
  • 乔xx

    乔xx2019-02-01 15:30:56

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

    reply
    0
  • 过客

    PHP double quotes can directly parse variables. When operating a database, I just add two more dots like that.

    过客 · 2019-02-03 09:40:41
  • Cancelreply