I have 18 fields in my MySql db. I have a query that works great until I add a new field to upload. I receive the error message: PHP Fatal error: Uncaught Error: Call to a member function execute() on bool in /home/…
I have removed the field and it works again. I have removed a different field and it works fine with the new field. Is there a length error or a field count error that would be the cause?
Here is the snippet where the error is generated, in the execute statement.
if(isset($_POST['productname'])){
$product = htmlentities($_POST['productname']);
$imgproductname = strtolower(str_replace(" ", "_", (htmlentities($_POST['productname']))));
$origin = htmlentities($_POST['origin']);
$l1perlb = htmlentities($_POST['l1perlb']);
$l2perlb = htmlentities($_POST['l2perlb']);
$l3perlb = htmlentities($_POST['l3perlb']);
$l1perkg = htmlentities($_POST['l1perkg']);
$l2perkg = htmlentities($_POST['l2perkg']);
$l3perkg = htmlentities($_POST['l3perkg']);
$costlb = htmlentities($_POST['costlb']);
$costkg = htmlentities($_POST['costkg']);
$quantity= htmlentities($_POST['quantity']);
$source = htmlentities($_POST['source']);
$comment = htmlentities($_POST['comment']);
$preview = htmlentities($_POST['preview']);
$image = '"https://mywebsite.com/images/' . $imgproductname . '.' . $ext . '"';
$image = '<a href=' . $image . '>View Pic</a>';
$ip = $_SERVER['REMOTE_ADDR'];
$sql ='INSERT INTO product(productname, origin, l1perlb, l2perlb, l3perlb, l1perkg, l2perkg, l3perkg, costlb, costkg, quantity, source, comment, image, ip) VALUES(:productname, :origin, :l1perlb, :l2perlb, :l3perlb, :l1perkg, :l2perkg, :l3perkg, :costlb, :costkg, :source, :comment, :preview, :image, :ip)';
$stmt = $pdo->prepare($sql);
$stmt->execute(['productname'=>$product, 'origin'=>$origin, 'l1perlb'=>$l1perlb, 'l2perlb'=>$l2perlb, 'l3perlb'=>$l3perlb, 'l1perkg'=>$l1perkg, 'l2perkg'=>$l2perkg, 'l3perkg'=>$l3perkg, 'costlb'=>$costlb, 'costkg'=>$costkg, 'source'=>$source, 'comment'=>$comment, 'preview'=>$preview, 'image'=>$image, 'ip'=>$ip]);
The error arrived when I added preview=>$preview in the execute statement.
The query is fine when I remove this field.