第十三周总结
所花时间:1天+1下午
代码行:800(PHP)+700(java web)
博客量:1篇
了解到知识点 :
解决phpmyadmin数据库乱码问题:
选择 数据库时:gbk_chinese_ci
表:gbk_chinese_ci
解决输出数据库结语句:
1 header ( "Content-type: text/html; charset=utf-8" ); //设置文件编码格式 2 $name=$_GET['name']; 3 $sex=$_GET['sex']; 4 $id=$_GET['id']; 5 $s="先生"; 6 if($sex=='女') 7 $s="小姐"; 8 echo "<h3>$name $s 您好,对不起,没有找到您的个人资料,请填写您的详细信息!</h3>"; 9 echo"<hr/>"; 10 $name=" "; 11 $sex=" "; 12 $favor=" "; 13 $home=" "; 14 $other=" "; 15 $sql=" "; 16 $id=0; 17 if(!empty($_POST)) 18 { 19 $conn = new MySQLi("localhost","root","","tect"); 20 //判断是否连接成功 21 // mysqli_query($conn,"set names utf-8"); 22 mysqli_set_charset($conn,'utf8'); 23 mysqli_connect_error()?die("连接失败"):""; 24 $name=$_POST['name']; 25 $sex=$_POST['sex']; 26 $favor=$_POST['favor']; 27 $home=$_POST['home']; 28 $id=$_POST['Id']; 29 $sql = "insert into user (Id,Name,Sex,Favor,Home,Other) values('{$id}','{$name}','{$sex}','{$favor}','{$home}','{$other}')";//波尔型数据往里添加时不能有‘’,添加字符串的话永远返回的是true。 30 if($conn->query($sql)==TRUE) 31 { 32 echo "<script>alert('您的资料保存成功!');location='ex02a.php?id=$id';</script>"; 33 } 34 else{ 35 echo "ERROR".$sql."<br>".$conn->error; 36 } 37 }
解决jsp中连接数据库问题:
1 <body> 2 <% 3 request.setCharacterEncoding("utf-8"); 4 String id = request.getParameter("id"); 5 String name = request.getParameter("name"); 6 String sex = request.getParameter("sex"); 7 String time = request.getParameter("time"); 8 String address = request.getParameter("address"); 9 Class.forName("com.mysql.jdbc.Driver"); 10 Connection con = DriverManager.getConnection( 11 "jdbc:mysql://localhost:3306/studentmanagement?&&useSSL=false&serverTimezone=UTC", "root", 12 "zb753951"); 13 14 15 String sql = "update student set name=?,gender=?,birthday=?,address=?where sno=?"; 16 PreparedStatement stmt = con.prepareStatement(sql); 17 stmt.setString(5, id); 18 stmt.setString(1, name); 19 stmt.setString(2, sex); 20 stmt.setString(3, time); 21 stmt.setString(4, address); 22 23 int i = stmt.executeUpdate(); 24 25 if (i == 1) { 26 out.println("<h2>修改成功!</h2><br/>"); 27 out.println("<a href='index.jsp'>返回首页</a>"); 28 } else { 29 out.println("<h2>修改失败!</h2><br/>"); 30 out.println("<a href='edit.jsp?id='" + id + ">重新添加</a>"); 31 } 32 stmt.close(); 33 con.close(); 34 %> 35 </body>