php中调用include中的函数。结果显示未定义。请问怎么解决?代码如下:
config.php:
<?php
$servername = "localhost";
$username = "root";
$password = "123456";
$mysql_database="login";
// 创建连接
$conn = mysqli_connect($servername, $username, $password,$mysql_database);
// 检测连接
if($conn->connect_error){
die('connect error:'.$conn ->connect_errno);
}
// 设置数据库字符集
$conn->set_charset('UTF-8');
$result = $conn->query('select * from register');
$data = $result->fetch_all(); // 从结果集中获取所有数据
print_r($data);
?>
register.php:
<?php
header("Content-type:text/html;charset=utf-8");
//链接数据库
include_once 'config.php';
$temp_pwd1=$_POST['pwd1'];
$temp_pwd2=$_POST['pwd2'];
$temp_username=$_POST['username'];
if($temp_pwd1==""||$temp_pwd2==""||$temp_username==""){
echo"<script>alert('请将表单填写完整!');</script>";
echo"<script>window.history.go(-1);</script>";//返回上一页
}
elseif($temp_pwd1!=$temp_pwd2)
{
echo"<script>alert('两次密码不正确');window.history.go(-1);</script>";
}
// 判断用户名是否重复
$userNameSQL = "select * from register where username = '$temp_username'";
$result=mysqli_query($conn,$userNameSQL);
$row=mysqli_num_rows($result);
?>
运行结果及报错内容
register.php显示未定义的变量 ''$conn''