-3

I've been trying to update an old php/mysql form to update data to database. so far, its been crazy. I have gotten passed the errors of getting in the server and database, now I am having another issue that I cannot solve.

The error:

Fatal error: Uncaught ArgumentCountError: mysqli_query() expects at least 2 arguments...on line 153

Here are lines 153 - 160 :

If(!mysqli_query($query))
    {
      echo "Error adding the comments to the DB." . mysqli_error();
      mysqli_close($dbconnect);
      exit();
    }
      else
    {
  • 1
    mysqli_query($con, $query) -- $con is the connection – Ken Lee May 31 '22 at 01:13
  • 1
    See [this info](https://stackoverflow.com/questions/1390607/how-to-change-mysql-to-mysqli) as one source, but also consider [PDO, as this answer suggests](https://stackoverflow.com/a/16220469/7644018) as another potential upgrade. To PDO, here is a [great tutorial](https://phpdelusions.net/pdo) on the topic. – Paul T. May 31 '22 at 01:39

1 Answers1

-2

If you want to display error in connection:

$connect=mysqli_connect("localhost","root","","db");
if(!$connect){
 echo"There are error in connect".mysqli_error();}

in your code you check if query, if you want to check query.. the best way:

$sql="select * from table_name";
$query=mysqli_query($connect,$sql);
if($query){
//do your code..
}else{
  echo "Error adding the comments to the DB." . mysqli_error();
  mysqli_close($dbconnect);
  exit();
}