0

I have searched every single one of these forms, however I still cant figure this out. I've been stuck on it for hours.

Here is my code

 <?php
//$success = 0;
//process login form if submitted
error_reporting(E_ALL);
ini_set('display_errors', 1);
if(isset($_POST['profileSubmit']))
{
   if (empty(($_POST['first_name']) || ($_POST['last_name']) || 
     ($_POST['age']) || ($_POST['mobile']) || ($_POST['location']) ||
    ($_POST['email']) || ($_POST['password']) ||($_POST['verify_password'])))
{
    $error[] = "Please fill out all fields";
}

if (($_POST['password']) != ($_POST['verify_password']))
{
    $error[] = "Please make sure your password matches";
}

else
{
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $age = $_POST['age'];
    $mobile = $_POST['mobile'];
    $location = $_POST['location'];
    $email= $_POST['email'];
    $password = ($_POST['password']);
    $username= 'username1';

    $sql='SELECT username FROM Accounts WHERE username=?';
    $stmt=$conn->prepare($sql);
    $stmt->bind_param('s',$username);
    $stmt->execute();
    $stmt->bind_result( $found );
    $stmt->fetch();
    if($found)
    {

        $hashed_password = password_hash($_POST['password'], PASSWORD_DEFAULT);
        $hash = substr( $hashed_password, 0, 60 );

        $sqli= 'UPDATE Accounts SET first_name= ?';
        $stmt=$conn->prepare( $sqli );
        echo $conn->error;
        $stmt->bind_param('s',$first_name);

        $success = "Your Profile has been Updated Successfully";
        $stmt->execute();
        $stmt->close();

    }
}

}

When I run this I get Fatal error: Call to a member function bind_param() on boolean. I dont understand why my prepare is failing.. It is failing on $stmt->bind_param('s',$first_name);

Also this is the config code.

enter $db_name="stockTest";
$server_name = "localhost";
$username = "root";
$password = "";

// Create connection
$conn = new mysqli($server_name,$username, $password,$db_name);
///Check connection
if ($conn->connect_error)
{
    echo $conn->error;
    die("Connection failed: " . $conn->connect_error);
}

Thank you

Chris
  • 361
  • 1
  • 4
  • 17
  • Don't you think you forgot to add a WHERE clause in your query, to just update a specific account's first_name? – Tushar Jul 08 '20 at 01:50
  • I had that before, but I'm trying to limit the amount of variables to try to debug this so I removed it. – Chris Jul 08 '20 at 01:52
  • You should include the code for creating the `$conn` object. The root problem is quite possibly earlier in your code. – akenion Jul 08 '20 at 01:54
  • Oh ok, i will add that right now – Chris Jul 08 '20 at 01:56
  • Is there no output from `echo $conn->error;`? – akenion Jul 08 '20 at 02:04
  • And where is $first_name defined? – Booboo Jul 08 '20 at 02:05
  • I dont get output. My page turns blank with only fatal error code showing – Chris Jul 08 '20 at 02:05
  • I updated to show the full php file – Chris Jul 08 '20 at 02:07
  • Can you change your `echo` to a `var_dump` and add an exit immediately afterwords(before the `bind_param` call? Also, be sure to view the source of the page rather than looking at rendered HTML as the error may be output in a location that would not be displayed. – akenion Jul 08 '20 at 02:11
  • I figured it out. "Commands out of sync; you can't run this command now".. Now to figure out how to fix this lol – Chris Jul 08 '20 at 02:18
  • got it!!! I had to add a stmt->close() right after I fetch, so I don't run two sqli statements at the same time. – Chris Jul 08 '20 at 02:23

0 Answers0