So I am not really sure why I can't use the same variables that I am using in this echo statement for my prepared statement to insert the data to a mysql table. It gives me a boolean for the value. I am sure I am overlooking something but I can't seem to figure out what.
Should I store the values in a separate array and then pull them out one by one? Seems redundant...
ERROR: PHP Fatal error: Call to a member function bind_param() on boolean in functions/functions.php on line 3764
Not a duplicate of the suggestion I am getting a boolean on the variable
global $con;
require "sendgrid-php/set_api.php";
$apiKey = getenv('SENDGRID_API_KEY');
$sg = new \SendGrid($apiKey);
$response = $sg->client->contactdb()->lists()->get();
$json_response = json_decode($response->body(), true);
foreach($json_response as $key){
foreach($key as $type=>$value){
$cat_id = $value['id'];
$cat_name = $value['name'];
$rec_count = $value['recipient_count'];
echo "<option value='$cat_id'>$cat_name ($rec_count)</option>";
$catid = $cat_id;
$qry2 = $con->prepare("SELECT sg_id from email_campaign_categories where sg_id = ? ");
$qry2->bind_param("s", $catid);
$catid = $cat_id;
$qry2->execute();
$qry2->store_result();
if($qry2->num_rows < 1){
$ins_qry = $con->prepare("INSERT into email_campaign_categories(name,sg_id) VALUES(?,?)");
$ins_qry->bind_param("ss", $catid, $cat_name);
$ins_qry->execute();
}
}
}
WORKING CODE:
global $con;
require "sendgrid-php/set_api.php";
$apiKey = getenv('SENDGRID_API_KEY');
$sg = new \SendGrid($apiKey);
$response = $sg->client->contactdb()->lists()->get();
$json_response = json_decode($response->body(), true);
foreach($json_response as $key){
foreach($key as $type=>$value){
$cat_id = $value['id'];
$cat_name = $value['name'];
$rec_count = $value['recipient_count'];
echo "<option value='$cat_id'>$cat_name ($rec_count)</option>";
$cat_id = $value['id'];
$cat_name = $value['name'];
$rec_count = $value['recipient_count'];
$catid = $cat_id;
$qry->free_result();
$qry2 = $con->prepare("SELECT sg_id from email_campaign_categories where sg_id = ? ");
echo $con->error;
$qry2->bind_param("s", $catid);
$qry2->execute();
$qry2->store_result();
if($qry2->num_rows < 1){
$qry2->free_result();
$ins_qry = $con->prepare("INSERT into email_campaign_categories(name,sg_id) VALUES(?,?)");
$ins_qry->bind_param("ss", $catid, $catname);
$catid = $cat_id;
$catname = $cat_name;
$ins_qry->execute();
}
}