0

This project ran smoothly before, and I already hosted it on heroku. When I try to download the source code and run the project locally, it throws some errors. The first error is:

[Fri May 26 17:08:01 2023] [::1]:49688 [200]: POST /Admin/reg_StoreManager.php - Uncaught Error: Call to a member function execute() on bool in C:\xampp\htdocs\s51914-dzihniboutique\Admin\reg_StoreManager.php:34 Stack trace: #0 {main} thrown in C:\xampp\htdocs\s51914-dzihniboutique\Admin\reg_StoreManager.php on line 34

Here is the code:

/Admin/reg_StoreManager.php

 <?php
 error_reporting(0);
 include_once '../database.php';
 include_once 'session.php';
 session_start();
 ?>
    <?php
          if (isset($_POST['reg_StoreManager'])) {

  try {

  $stmt = $conn->prepare("INSERT INTO storemanager(StoreManagerFullName, StoreManagerName, 
  StoreManagerPass, StoreManagerEmail,StoreManagerPhone, StoreManagerAddress) VALUES(?,?,?,?,?,?)");

// //$stmt->bindParam(':outsider_id', $outsider_id, PDO::PARAM_STR);
// $stmt->bindParam(':StoreManagerFullName', $StoreManagerFullName, PDO::PARAM_STR);
// $stmt->bindParam(':StoreManagerName', $StoreManagerName, PDO::PARAM_STR);
// $stmt->bindParam(':StoreManagerPass', $StoreManagerPass, PDO::PARAM_STR);
// $stmt->bindParam(':StoreManagerEmail', $StoreManagerEmail, PDO::PARAM_STR);
// $stmt->bindParam(':StoreManagerPhone', $StoreManagerPhone, PDO::PARAM_STR);
// $stmt->bindParam(':StoreManagerAddress', $StoreManagerAddress, PDO::PARAM_STR);

   
//$outsider_id = $_POST['outsider_id'];
// $StoreManagerFullName = $_POST['StoreManagerFullName'];
// $StoreManagerName = $_POST['StoreManagerName'];
// $StoreManagerPass = md5($_POST['StoreManagerPass']);
// $StoreManagerEmail =  $_POST['StoreManagerEmail'];
// $StoreManagerPhone =  $_POST['StoreManagerPhone'];
// $StoreManagerAddress =  $_POST['StoreManagerAddress'];

// $stmt->bind_param("ssssss", $s_name, $username, $s_pass, $s_email, $s_phone, $s_address);

   
$stmt->execute();
echo '<script type="text/javascript">'; 
echo 'alert("New Account has been registered!");'; 
echo 'window.location.href = "RegisterStoreManager.php";';
echo '</script>';
//header('Location: RegisterStoreManager.php');
}

catch(PDOException $e)
{
  echo "Error: " . $e->getMessage();
}
}
?>

echo '<script type="text/javascript">'; 
echo 'alert("New Account has been registered!");'; 
echo 'window.location.href = "RegisterStoreManager.php";';
echo '</script>';
// header('Location: RegisterStoreManager.php');
}

Line 34 is $stmt->execute();

ADyson
  • 57,178
  • 14
  • 51
  • 63
  • 1
    "_Call to a member function execute() on bool_" means you are trying to call a method `execute()` on a `bool` - not an object. So, `$stmt` is a `bool` (from `$stmt = $conn->prepare(...)`). You prepare the query but don't bind params. Which values would that query insert? – brombeer May 26 '23 at 09:35
  • From PHP's [md5](https://www.php.net/manual/en/function.md5.php) manual: "_Warning It is not recommended to use this function to secure passwords, due to the fast nature of this hashing algorithm. See the [Password Hashing FAQ](https://www.php.net/manual/en/faq.passwords.php#faq.passwords.fasthash) for details and best practices._" – brombeer May 26 '23 at 09:36
  • fyi, you probably won't see your `alert()` since you redirect immediately after it – brombeer May 26 '23 at 09:37
  • @brombeer in JS, alert() blocks the thread, so it won't execute the location.href command until the user has closed the alert box – ADyson May 26 '23 at 10:03
  • 1
    @ADyson Oh ok, thanks, learned something today – brombeer May 26 '23 at 10:18

0 Answers0