学习:PHP MYSQL 写入数据库
新建test.php
<?php
$mysqli = new mysqli("localhost","root","","user");
if ($mysqli->connect_error) {
die($mysqli->connect_error);
}
$mysqli->query("set names utf8");
$username=$_POST['username'];
$wechat=$_POST['wechat'];
$tel=$_POST['tel'];
$result = $mysqli->query("INSERT INTO test (username,wechat,tel)
VALUES ('$username','$wechat','$tel')");
if ($result){
echo "添加成功";
}else {
echo "添加失败";
}
$mysqli->close();
?>
<form action="test.php" method="POST">
username: <input type="text" name="username">
wechat: <input type="text" name="wechat">
tel: <input type="text" name="tel">
<input type="submit" value="提交">
</form>