<?php
$link = mysqli_connect('localhost', 'root', 'root', 'database9');
mysqli_query($link,"set names utf8");//设置数据库编码格式utf8
/* 检测连接是否成功 */
if (!$link) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* 检测是否生成MySQLi_STMT类 */
$stmt = mysqli_prepare($link, "insert into member (email,password,tel) VALUES (?, ?, ?)");
if ( !$stmt ) {
die('mysqli error: '.mysqli_error($link));
}
/* 获取POST提交数据 */
$email = $_POST['email']; //接收email
$password = $_POST['password']; //接收password
$tel = $_POST['tel']; //接收tel
/* 参数绑定 */
mysqli_stmt_bind_param($stmt, 'sss', $email, $password, $tel);
/* 执行prepare语句 */
mysqli_stmt_execute($stmt);
/* 根据执行结果,跳转页面 */
if(mysqli_stmt_affected_rows($stmt)){
echo "<script>alert('添加成功');window.location.href='index.php';</script>";
}else{
echo "<script>alert('添加失败');</script>";
}
?>