0

I am calling this function from another page, but it gives me the below error: Warning: mysqli::prepare(): Couldn't fetch mysqli in

public function ResetTalentCandidate() {
    // Get global vars
    global $conn;
    global $authUserId;

    // Get post data
    $candidateID = $_REQUEST['resetID'];
    $statusUpdate = 0;
    $dateReset = time();

    if ($stmt = $conn->prepare ("UPDATE `rf_opportunitypool` SET pool_status = ? WHERE candidate_id = $candidateID;") or die (mysqli_error($conn))) {
        // Bind values
        $stmt->bind_param ('ii', $authUserId, $dateReset);

        // Execute query
        $stmt->execute();

        // Close statment
        $stmt->close();

        // Successfully updated
        return true;
    }

    // Nothing happened
    return false;
}

I have similar functions elsewhere in my class but don't have the same problem. Could I be missing something somewhere?

  • 2
    You have 1 placeholder and you bind 2 parameters – Mihai Sep 17 '15 at 06:41
  • Sorry, I actually had 3 placeholders, which I removed during testing. The problem is actually with the prepare statement and not the bind parameters. – Danny TwoTimes Sep 17 '15 at 06:43
  • Are you 100% confident about the content of $candidateID ? Can you show the actual string passed to prepare? – Amarnasan Sep 17 '15 at 06:45
  • So the original prepare is: if ($stmt = $conn->prepare ("UPDATE `rf_opportunitypool` SET `pool_status` = 0, `pool_change_by` = ?, `pool_change_date` = ? WHERE candidate_id = $candidateID;") or die (mysqli_error($conn))) { // Bind values $stmt->bind_param ('iii', $authUserId, $dateReset); // Execute query $stmt->execute(); // Close statment $stmt->close(); // Successfully updated return true; } – Danny TwoTimes Sep 17 '15 at 06:45
  • The content of $candidateID is an int like 5712032 – Danny TwoTimes Sep 17 '15 at 06:46
  • It seems you are not getting `$conn`, so the error is coming – Harshit Sep 17 '15 at 06:47
  • Will investigate $conn then – Danny TwoTimes Sep 17 '15 at 07:19
  • It turns out Harshit Shrivastava was correct. The $conn object was the issue. So DatabaseDisconnect () was being called somewhere in the system by another file before my method. So I just had to call it before this file and all is good now. Thanks for the assistance everyone. – Danny TwoTimes Sep 17 '15 at 09:13

0 Answers0