当前位置: 首页 > 面试题库 >

Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in C:\ [duplicate]

汝楷
2023-03-14
问题内容

This question already has answers here :

Warning: mysqli_query() expects at least 2 parameters, 1 given. What?
[duplicate]
(2 answers)

Closed 5 years ago.

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: enter image description
here

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.



 类似资料:
  • 问题内容: 我在jsp页面中看到以下错误- 我看到了一篇关于此的文章,并尝试了一些建议的方法。BalusC提供了很好的输入- JSTL1.2和Standard.jar不能一起使用。我做到了,它解决了一段时间的问题- 但它再次出现。我不确定是否还有jar碰撞。我已经将所有jar定义为Maven中的依赖项。以下是我指定的依赖项pom.xml- 问题答案: 您将需要在项目中导入JSP API,而Serv

  • 问题内容: This question already has answers here : How to nicely format floating numbers to String without unnecessary decimal 0? (26 answers) Closed 6 years ago. For example I need to become , or to beco

  • 问题内容: 我正在创建一个需要存储键值对的程序。该程序需要接受键形式的请求,并返回相应的值。 问题在于每个键有时有多个值,并且map类不允许重复的键。 这些值是数字,因此无法像使用字符串那样有意义地连接这些值。 对于每个键可以有多个数值的事实,是否有任何优雅的解释方法?我希望返回每个数字,而不是随机返回一个数字。 问题答案: $ cat YourMap.java public class Your

  • 问题内容: 从MySQL 4.1.0开始,可以在目标表wrt 或某个字段中已经插入的值(使用或或)时添加语句来指定行为。如果表中已经有或个字段的值,则将其替换为。 如果我的表中有多个 字段,该如何处理? 如果任一字段匹配,我只能进行一次更新吗? 仅当两个字段同时匹配时才能更新吗? 问题答案: 考虑 如果a和b是字段,则发生在。同样,当两个或多个条目满足条件时,更新仅执行一次。 此处带有ID和Nam

  • 问题内容: 我已经找到了单独使用mySQL的一些答案,但是我希望有人可以向我展示一种使用PHP处理插入/更新时获取mysql DB最后插入或更新的行的ID的方法。 当前,我有类似这样的内容,其中column3是唯一键,还有一个id列是自动递增的主键: $ my_id在INSERT上是正确的,但是在更新行时(在DUPLICATE KEY UPDATE上)是错误的。 我见过一些人建议您使用类似 在调用

  • 问题内容: 我知道,如果已经有该键的记录,您可以用来更新某个值, 我可以做这个: 但是,如何做到这一点而不必两次写出列和值呢? 问题答案: 不幸的是没有。 您可以不必重复该值而达到一半: 但是您仍然必须列出这些列。

  • 问题内容: 我对MySQL的INSERT … ON DUPLICATE KEY UPDATE 语句的返回值感到困惑。当我在MySQL客户端(mysql终端,phpmyadmin或MySQL Workbench)上尝试使用它时,执行结果将显示以下内容之一: 1 :如果插入了新记录(即没有重复的密钥)。 2 :如果存在重复记录,则更新现有记录。 0 :如果执行更新,但没有更改列值。 这些结果是有道理的

  • 问题内容: 我有一个带有列的基本表: id(主要用于AI) 名称(唯一) 等等 如果唯一列不存在,则插入行,否则更新行…。 问题在于,如果它执行UPDATE,则id列上的auto_increment值会上升。因此,如果执行了大量更新,则id auto_increment会通过屋顶。 显然这是一个错误:http : //bugs.mysql.com/bug.php?id=28781 …但是我在共享主