PHP 7.2.7 warning: Use of undefined constant

Peter Festejo picture Peter Festejo · Aug 7, 2018 · Viewed 47.8k times · Source

So after I click submit on my index.php resgitration form. It all went good name, email, and password is saved from my database. But there is a warning that irrates me.

Use of undefined constant result_query - assumed 'result_query' (this will throw an Error in a future version of PHP)

Appears.

It said it is in line 26.

Here is my code on my function.php where the warning is coming from.

<?php include "db.php" ?>
<?php

function createAccount(){
global $connection;
if(isset($_POST['submit'])){

    $name = $_POST['name'];
    $email = $_POST['email'];
    $password = $_POST['password'];

    $name = mysqli_real_escape_string($connection, $name);
    $passowrd = mysqli_real_escape_string($connection, $password);

    $hashFormat = "$2y$10$"; // blowfish encryting
    $salt = "dikoalampasswordqweqwe";
    $hashAndSalt = $hashFormat . $salt;

    $password = crypt($password, $hashAndSalt);

    $query = "INSERT INTO accounts_registered(name, email, password) ";
    $query .= "VALUES ('$name', '$email', '$password')";

    $result_query = mysqli_query($connection, $query);

    if(!result_query){
        die("Query Failed" . mysqli_error($connection));
    }
    else {
      $message = "Account Registered";
      echo "<script type='text/javascript'>alert('$message');</script>";

      }
   }
}


?>

Answer

Adam Johnston picture Adam Johnston · Aug 7, 2018

if(!result_query) should be if(!$result_query)