connect.php
<?php
header("Content-type: text/html; charset=utf8");
//1. 声明字符编码
$host = '127.0.0.1'; //数据库ip
// $host='localhost';//数据库ip
$user = 'root'; //用户名
$password = '密码'; //密码
$dbName = 'test'; //要连接的数据库名
$con = new mysqli($host, $user, $password, $dbName, 3306); //数据库连接
if ($con->connect_error) {
echo "系统异常,连接数据库失败:", $con->connect_error;
} //else {
//echo "连接成功</br>";
//}
?>
write.php
<?php
header("Content-type: text/html; charset=utf8");
include 'connect.php'; //调用connect.php文件
$my_table = 'stu';
$open_id = $_GET['open_id'];
$name = $_GET['name'];
if ($con->connect_error) {
die("连接失败:" . $con->connect_error);
} else {
$sql = "INSERT INTO $my_table(open_id,name) VALUES