1.employeeInf.html頁面提供用戶信息的錄入,如下圖所示:
2.employeeInf.html源代碼如下圖所示:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Insert the information of employee!</title> </head> <body> <form action="shishi2.php" method="post"> 工號:<input type="text" name="gonghao" /> 姓名:<input type="text" name="name"/> 地址:<input type="text" name="address"/> <input type="submit" /> </form> </body> </html>
3.shishi2.php源代碼如下所示;主要負責向MySQL數據庫中插入數據;
<?php //第一種鏈接mysql數據庫的代碼方式; $con = mysqli_connect('localhost','root','rootroot'); if(!$con) { echo "link failly"; } else { // echo "link successfully"; // echo $_POST[gonghao]; mysqli_select_db($con,"finance"); $sql="insert into yuangonginf(gonghao,name,address) values ('$_POST[gonghao]','$_POST[name]', '$_POST[address]')"; //if(!mysqli_query($con,"insert into yuangonginf(gonghao,name,address) values ('1002','lisi', 'Wuhan,BayiRoad')")) if(!mysqli_query($con, $sql)) { die('Error:'.mysqli_error($con)); } else { echo "One record added"; mysqli_close($con); } }