<?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); ?>
航航2019-02-14 11:06:55
Firstly, mysql requires quotation marks when inserting Chinese characters. Secondly, php dots are used to connect characters
乔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