警告:mysqli_select_db()恰好需要2个参数,其中1个在C:\中给出 [英] Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in C:\
问题描述
我正在做一个教程,其中作者尚未更新其内容以反映PHP文档中的更改.无论如何,我需要知道我要提供的参数是什么.我检查了所有事情是否井井有条,但是我真的不知道该怎么办.这就是我所拥有的:
Connects.php
<?php
$connect_error = 'Sorry, we\'re experiencing connection issues.';
$con = mysqli_connect('localhost', 'root', 'PwdSQL5');
mysqli_select_db('phpcadet') or die($connect_error);
?>
但是我得到了错误:
在解决了Connects.php问题之后,这就是为什么我得到修复的原因...更多错误,这是我的代码.请记住,我是PHP的新手,并且正在学习一个拙劣的教程.
警告::mysqli_real_escape_string()期望参数1为mysqli,第4行的C:\ vhosts \ phpcadet \ core \ functions \ general.php中给出的字符串
General.php
<?php
function sanitize($data)
{
return mysqli_real_escape_string($data, 'What goes here?');
}
?>
然后这样:警告:mysqli_query()期望参数1为mysqli,第7行的C:\ vhosts \ phpcadet \ core \ functions \ users.php中给出的字符串
Users.php
<?php
require 'core/database/connects.php';
function user_exists($username)
{
$username = sanitize($username);
$query = mysqli_query($_POST['username'], "SELECT * FROM users");
$row = mysqli_fetch_array($query);
if($row['username']==$username)
{
echo "Welcome, $username!";
return true;
}
else echo "Please enter a valid username and password";
return false;
}
function user_active($username)
{
$username = sanitize($username);
$query = mysqli_query($_POST['username'], "SELECT * FROM users");
$row = mysqli_fetch_array($query);
if($row['username']==$username && $row['active']==1)
{
echo "Welcome, $username!";
return true;
}
else echo "Your username and password could not be verified.";
return false;
}
?>
最后,这是:警告:mysqli_fetch_array()期望参数1为mysqli_result,在第8行的C:\ vhosts \ phpcadet \ core \ functions \ users.php中给出空值
在上方查看相同的代码
我的一些代码是其他答案的汇编,可以解决本课中的问题,并且可以在Stack上找到.由于它们之间的不一致,这使我很难了解发生了什么...来自另一种语言,在这里我不太熟悉,只需要帮助,所有这些都可以单击.然后,我将对手册的内容有了解".谢谢.
mysqli_select_db()
应该具有 2 参数,连接链接和数据库名称-
mysqli_select_db($con, 'phpcadet') or die(mysqli_error($con));
在die语句中使用mysqli_error
会告诉您准确是什么错误,而不是一般错误消息.
I'm doing a tutorial in which the author has not updated his content to reflect changes in the PHP documentation. Anyways, I need to know what is parameter is being asked of me to provide. I've checked that all things are in order, but I literally don't know what I'm supposed to provide. Here's what I have:
Connects.php
<?php
$connect_error = 'Sorry, we\'re experiencing connection issues.';
$con = mysqli_connect('localhost', 'root', 'PwdSQL5');
mysqli_select_db('phpcadet') or die($connect_error);
?>
And yet I get the error:
Edit: After figuring out to resovle the Connects.php issue, here's why I get when fixed it... more errors and here's my code. Remember I'm new to PHP and am following a poorly done tutorial.
Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in C:\vhosts\phpcadet\core\functions\general.php on line 4
General.php
<?php
function sanitize($data)
{
return mysqli_real_escape_string($data, 'What goes here?');
}
?>
Then this: Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\vhosts\phpcadet\core\functions\users.php on line 7
Users.php
<?php
require 'core/database/connects.php';
function user_exists($username)
{
$username = sanitize($username);
$query = mysqli_query($_POST['username'], "SELECT * FROM users");
$row = mysqli_fetch_array($query);
if($row['username']==$username)
{
echo "Welcome, $username!";
return true;
}
else echo "Please enter a valid username and password";
return false;
}
function user_active($username)
{
$username = sanitize($username);
$query = mysqli_query($_POST['username'], "SELECT * FROM users");
$row = mysqli_fetch_array($query);
if($row['username']==$username && $row['active']==1)
{
echo "Welcome, $username!";
return true;
}
else echo "Your username and password could not be verified.";
return false;
}
?>
And finally this: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\vhosts\phpcadet\core\functions\users.php on line 8
See same code above
Some of my code is a compilation of other answers to solve issues with the lesson, and were found on Stack. Due to inconsistecy of them, it makes it hard for me to pick up what is going on... Coming from a different language, I not that familiar here, and just need the help, so it all clicks. Then I'll have "understanding" of what the manual is saying. Thanks.
mysqli_select_db()
should have 2 parameters, the connection link and the database name -
mysqli_select_db($con, 'phpcadet') or die(mysqli_error($con));
Using mysqli_error
in the die statement will tell you exactly what is wrong as opposed to a generic error message.
这篇关于警告:mysqli_select_db()恰好需要2个参数,其中1个在C:\中给出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!