query("select *-6ren">
gpt4 book ai didi

php - 我的 mysql 和 php 有问题

转载 作者:行者123 更新时间:2023-11-29 15:02:34 24 4
gpt4 key购买 nike

我有一个问题,这是我的代码:

   $db = new mysqli("localhost", "root", "", "blah");

$result1 = $db->query("select * from c_register where email = '$eml' and password = '$pass'");

if($result1->fetch_array())

{

$auth->createSession();

$_SESSION['user'] = 'client';

promptUser("You have successfully logged in!!!","index.php");
}

$db = new mysqli("localhost", "root", "", "blah");

$result2 = $db->query("select * from b_register where email = '$eml' and password = '$pass'");
if($result2->fetch_array())

{

$auth->createSession();

$_SESSION['user'] = 'business';

promptUser("You have successfully logged in!!!","index.php");
}
$db = new mysqli("localhost", "root", "", "blah");

$result3 = $db->query("select * from g_register where email = '$eml' and password = '$pass'");
if($result3->fetch_array())

{

$auth->createSession();

$_SESSION['user'] = 'employee';

promptUser("You have successfully logged in!!!","index.php");
}

$db = new mysqli("localhost", "root", "", "blah");

$result4 = $db->query("select * from k_register where email = '$eml' and password = '$pass'");
if($result4->fetch_array())

{

$auth->createSession();

$_SESSION['user'] = 'super';

promptUser("You have successfully logged in!!!","index.php");
}
else

{

promptUser("Username/Password do not match. Please try again!!!","");
}

有趣的是,这段代码可以工作,但我不知道我的做法是错误的。我是 php 和 mysql 的新手,所以请帮忙。我还尝试了例如 result4->free(); 对于保存数据的所有变量,我收到此错误: fatal error :在非对象上调用成员函数 free() -对象在...

最佳答案

不要重复自己。您已经创建了 mysqli 对象,因此可以重用它。例如:

$db = new mysqli("localhost", "root", "", "blah");
$result1 = $db->query("select * from c_register...");
$result2 = $db->query("select * from d_register...");
$result3 = $db->query("select * from e_register...");

这将使您的代码更清晰,并且以后更容易修改。

关于php - 我的 mysql 和 php 有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2783228/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com