mysqli_query不接受我的mysqli_connect和正确使用mysqli_query参数


mysqli_query not accepting my mysqli_connect and proper use of parameters of mysqli_query

我已经在不同的页面上设置了我的configdb.php并将其包含在我的其他PHP页面上。

这是我的配置数据库.php

<?php
$hostname ="localhost";
$username ="root";
$password ="";
$db ="practicedb";
$connect = mysqli_connect($hostname,$username,$password) or die("cannot connect to server");
mysqli_select_db($connect,$db) or die("database not found!");
?>

这些是我得到的错误:

Notice: Undefined variable: configdb in /Applications/XAMPP/xamppfiles/htdocs/practicesystem/add.php on line 14
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /Applications/XAMPP/xamppfiles/htdocs/practicesystem/add.php on line 14
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /Applications/XAMPP/xamppfiles/htdocs/practicesystem/add.php on line 15
Notice: Undefined variable: configdb in /Applications/XAMPP/xamppfiles/htdocs/practicesystem/add.php on line 28

这是我的添加.php我从以前的 PHP 页面的 $_POST 方法将项目插入数据库。

<?php
include "configdb.php";

$studid=$_POST['studid'];
$lastname=mysql_real_escape_string($_POST['lastname']);
$firstname= mysql_real_escape_string($_POST['firstname']);
$middlename= mysql_real_escape_string($_POST['middlename']);
$email=$_POST['email'];

$check = "SELECT * from studinfo where stud_id = '".$studid."'";
$qry = mysqli_query($configdb,$check);
$num_rows = mysqli_num_rows($qry); 

if($num_rows > 0){
// Here we are checking if username is already exist or not.
    echo "The person you have entered is already existing. Please try again.";
    echo '<a href="index.php">Try Again</a>';
    exit;
}
$query = "INSERT INTO studinfo (stud_id,lastname,firstname,middlename,email) VALUES ('".$studid."','".$lastname."','".$firstname."','".$middlename."','".$email."');";
//echo $query;
mysqli_query($configdb, $query);
echo "Thank You for Registration.";
echo '<a href="index.php">Click Here</a> to login you account.';
exit;
?>

我不知道,也不确定该在mysqli_query的第一个参数上放什么。我尝试将此代码放在它工作$con=mysqli_connect("localhost","root","","practicedb");,但它不切实际地将其放在我应该连接到数据库的每个 PHP 页面上......

另一个关于愚蠢错别字的问题......

$connect = mysqli_connect( ...
与。$qry = mysqli_query($configdb,$check);

所以错误消息清楚地说:未定义的变量:configdb