Ryan
Ryan

Reputation: 171

Prepared Statement error "No data supplied for parameters in prepared statement"

I am trying to update 2 different tables using a transaction. For my first query I get the error "No data supplied for parameters in prepared statement". my second query goes through just fine. I know that the error refers to the variables being passed to the $stmt->bind_param(). I have checked, triple checked and can confirm that all the vars that I am passing to it actually contain values. I have also checked to make sure the value being passed is correctly indicated by an 's' or an 'i'. My question is do I have a syntax error that would give me this error message or is there any other suggestion as to how I can fix it?

function updateClient($id,$first,$last,$email,$phone,$phoneCarrier,$tz,$wdh1,$wdh2,$weh1,$weh2,$goals){
global $conguest;
global $database;

$conguest->autocommit(false);  

//update the client tabel
$sql="UPDATE $database.client SET clientFirst = '?', clientLast = '?', clientEmail ='?', clientPhone =?, phoneCarrierId =?, timezoneId =?, clientHour1 ='?',clientHour2 ='?',clientHour3 ='?',clientHour4 ='?'
WHERE clientId = ?";

if($stmt = $conguest->prepare($sql)){        
    $stmt->bind_param('ssssiissssi', $first, $last, $email, $phone, $phoneCarrier, $tz, $wdh1, $wdh2, $weh1, $weh2, $id);
    $stmt->execute();        
    $clientupdate = $stmt->affected_rows;        
    $stmt->close();
}   
//update the goals table
$sql = "UPDATE $database.goal SET goalContent=?, categoryId = ?, goalDate=now() WHERE goalId = ?";

foreach ($goals as $goal) {
    if ($stmt = $conguest->prepare($sql)) {
        $stmt->bind_param('sii', $goal['goal'],$goal['cat'], $goal['id']);
        $stmt->execute();
        $i = $stmt->affected_rows;
        $stmt->close();
    }
    if($i){
        $goalupdate ++;
    }
}
//test that all updates worked
echo "$clientupdate, $goalupdate";
exit;
if($clientupdate ==1 && $goalupdate == 3){
    $conguest->commit();
    $conguest->autocommit(true);
    return 1;
}else{
    $conguest->rollback();
    $conguest->autocommit(true);
    return 0;
}    

}

Upvotes: 2

Views: 5768

Answers (1)

Olaf Dietsche
Olaf Dietsche

Reputation: 74018

Remove the single quotes around your placeholders. Replace

$sql="UPDATE $database.client SET clientFirst = '?', clientLast = '?', clientEmail ='?', clientPhone =?, phoneCarrierId =?, timezoneId =?, clientHour1 ='?',clientHour2 ='?',clientHour3 ='?',clientHour4 ='?' WHERE clientId = ?";

with

$sql="UPDATE $database.client SET clientFirst = ?, clientLast = ?, clientEmail = ?, clientPhone = ?, phoneCarrierId = ?, timezoneId = ?, clientHour1 = ?, clientHour2 = ?,clientHour3 = ?,clientHour4 = ? WHERE clientId = ?";

Furthermore, there's a newline before "where clientid". I don't know whether this is relevant.

Upvotes: 1

Related Questions