第十二周总结
所花时间:1天+1下午
代码行:600(PHP)
博客量:2篇
了解到知识点 :
PHP连接数据库:
1 <?php 2 /** 3 * Created by PhpStorm. 4 * User: 13313 5 * Date: 2019/5/18 6 * Time: 22:36 7 */ 8 header('Content-type:text/html;charset=utf-8'); 9 $name=" "; 10 $sex=" "; 11 $favor=" "; 12 $home=" "; 13 $other=" "; 14 $sql=" "; 15 $id=0; 16 if(!empty($_POST)) 17 { 18 $db = new MySQLi("localhost","root","","test"); 19 //判断是否连接成功 20 mysqli_connect_error()?die("连接失败"):""; 21 $name=$_POST['name']; 22 $sex=$_POST['sex']; 23 $favor=$_POST['favor']; 24 $home=$_POST['home']; 25 $other=$_POST['other']; 26 $sql = "insert into user (Name,Sex,Favor,Home,Other) values('{$name}','{$sex}','{$favor}','{$home}','{$other}')";//波尔型数据往里添加时不能有‘’,添加字符串的话永远返回的是true。 27 $db->query($sql); 28 if($db->query($sql)==TRUE) 29 { 30 echo"添加成功"; 31 } 32 else{ 33 echo "ERROR".$sql."<br>".$db->error; 34 } 35 } 36 37 38 ?>