Why has my PHP MySQL Verification code stopped working?

  mysql, php

So, I have code that submits a query and checks whether it was valid or not and returns a message based on that. It used to work months ago. Recently, I switched hosts (from Windows VPS to Linux).

The actual MySQL query itself works. It goes through to the database successfully, but the code is not checking it as successful.

if (Mysql_Update($sql)) // Send the query and check for completion.
{
    $success = "You have updated the records for <b>" . $firstName . " " . $lastName . "</b>";
    renderForm($id, $firstName, $lastName, $number, $email, NULL, $success);
}
else
{   // If the MySql Query fails, throw an error.
    echo danger("The MySql query has failed!");
    echo danger(mysqli_error($conn));
}

And here’s the break down of Mysql_Update

function Mysql_Query($query)
{
  global $conn; // Utilize the database connection.
  $query = mysqli_query($conn, $query) or die($conn->error);
  return $query;
}

function Mysql_Update($query)
{
  switch (isAdmin())
  {
    case true:
      Mysql_Query($query);
    break;

    default:
    ob_end_clean();
    die('You are not authorized to be in this area.');
    break;
  }
}

As I said before, the queries themselves go through and update the database. But my web-page is returning the error messages and for mysql_error($conn) it’s just an emtpy red box (danger() creates the red box). It used to work perfectly fine, this exact code, before switching to a new VPS. The old DB config also used the root user, but the new one uses an "admin" user granted with all DB privileges. I can’t figure out why these changes would matter. No other settings such as php.ini were transferred over, only inetpub.

Source: Ask PHP

LEAVE A COMMENT