先在你想显示的页面中添加表单用
<from action="index1.php" method="post"> //<from action="index1.php是向index1.php发送表单数据 method="post" post是传递方式
<input type="text" name="name" placeholder="姓名" required="">
<input type="password" name="mima" required=" " placeholder="密码至少6位数"><p></p> <input type="text" name="xingbie" placeholder="性别" required=""> <input type="text" name="xibu" placeholder="系部" required=""> <input type="text" name="banji" placeholder="班级" required=""> <input type="text" name="tex" placeholder="电话" required=""><button>确定</button>
<button>取消</button>
</from>
接下来在index1.中写php代码,
include_once("conn/conn.php"); //引入导入数据库
$name=$_POST["name"];
$mima=$_POST["mima"];$xingbie=$_POST["xingbie"]; // 括号里面的值对应前端里面name,post用来收集来自于表单的值存储在$...中$xibu=$_POST["xibu"];$banji=$_POST["banji"];$tex=$_POST["tex"];$sql="INSERT into user (name,mima,xingbie,xibu,banji,tex)values('$name','$mima','$xingbie','$xibu','$banji','$tex')";
$r=mysqli_query($link,$sql); ///INSERT into use括号中输入post中括号中的 values输入$..if ($r) { echo ("写入成功");}else{ echo ("失败");}在conn中创建一个conn.php固定的css代码
<?php
$host="localhost";$db_user="root"; //数据库用户$db_pass=""; //数据库密码$db_name="sqlclass1"; //数据库$timezone = "Asia/Shanghai";$link=mysqli_connect($host,$db_user,$db_pass,$db_name);
mysqli_query($link,"SET names UTF8");header("Content-Type: text/html; charset=utf-8");
date_default_timezone_set($timezone); //北京时间?>