guymclarenza Posted January 17, 2021 Share Posted January 17, 2021 if($pid != "") { $bname = $_REQUEST['bname']; $btitle = $_REQUEST['btitle']; $btags = $_REQUEST['btags']; $bdesc = $_REQUEST['bdesc']; $btext = $_REQUEST['btext']; $bimg = $_REQUEST['bimg']; $bimgalt = $_REQUEST['bimgalt']; $data = ""; if($bname!="") { $data = $data." 'bname' => ".$bname.", "; } if($btitle!="") { $data = $data."'btitle' => ".$btitle.", "; } if($btags!="") { $data = $data."'btags' => ".$btags.", "; } if($bdesc!="") { $data = $data."'bdesc' => ".$bdesc.", "; } if($btext!="") { $data = $data."'btext' => ".$btext.", "; } if($bimg!="") { $data = $data."'bimg' => ".$bimg.", "; } if($bimgalt!="") { $data = $data."'bimgalt' => ".$bimgalt.", "; } $data = $data."'pid ' =>". $pid.", " ; $data = "[".$data."]"; $build = ""; if($bname!="") { $build = $build." page_name = :bname,"; } if($btitle!="") { $build = $build." page_title = :btitle,"; } if($btags!="") { $build = $build." page_tags = :btags,"; } if($bdesc!="") { $build = $build." page_desc = :bdesc,"; } if($btext!="") { $build = $build." page_text = :btext,"; } if($bimg!="") { $build = $build." page_img = :bimg,"; } if($bimgalt!="") { $build = $build." page_imgalt = :bimgalt,"; } $build = $build." page_id = :pid"; $sql = "UPDATE pages SET ".$build." WHERE page_id=:pid"; echo $sql."<br /><br />"; echo $data."<br /><br />"; $stmt= $pdo->prepare($sql); $stmt->execute($data); Result of echo SQL and Data UPDATE pages SET page_name = :bname, page_title = :btitle, page_tags = :btags, page_desc = :bdesc, page_text = :btext, page_img = :bimg, page_imgalt = :bimgalt, page_id = :pid WHERE page_id=:pid [ 'bname' => Home, 'btitle' => Market Net, 'btags' => full stack development, search engine ready, professional web development, web design, 'bdesc' => Market net gives you online access to market traders country wide, Support Local businesses today, 'btext' => Market Net is the place for you to find those goodies you saw on the markets, buy them online and support small local businesses. Watch this space for more information. Test #D hvac , 'bimg' => supportlocal.jpg, 'bimgalt' => Support Local Small Businesses, 'pid ' =>106, ] Yet I am getting said error message. What am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/312012-php-warning-pdostatementexecute-expects-parameter-1-to-be-array-string-given-in/ Share on other sites More sharing options...
Strider64 Posted January 17, 2021 Share Posted January 17, 2021 Exactly what the error says $data is a string not an array. You also have other errors. Quote Link to comment https://forums.phpfreaks.com/topic/312012-php-warning-pdostatementexecute-expects-parameter-1-to-be-array-string-given-in/#findComment-1583817 Share on other sites More sharing options...
requinix Posted January 17, 2021 Share Posted January 17, 2021 I think you might have confused a PHP dump of an array with a string that looks like the PHP dump of an array. $data needs to be an array. Build that array in, probably, the most obvious way that you can think of. Quote Link to comment https://forums.phpfreaks.com/topic/312012-php-warning-pdostatementexecute-expects-parameter-1-to-be-array-string-given-in/#findComment-1583818 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.