Pdo Mysql Error Hy093
Contents |
here for a
Sqlstate[hy093]
quick overview of the site Help Center Detailed answers to pdostatement::execute(): sqlstate[hy093]: invalid parameter number: parameter was not defined any questions you might have Meta Discuss the workings and policies of this site About Us Learn pdo errorinfo more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community
Pdo Param_str
Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error HY093 with a MySQL Insert PDO Request up vote 3 down vote favorite 1 After reading all others questions about the HY093 I open this one to figure out why I've got this message too. Here is my table : And here is my request : (Where $conn is my PDO connection) $sql = $conn->prepare("INSERT INTO Sites (Email,URL,Title,Description,PageRank,Rewrite,MetaDesc,Origin,BackLink,nbBackLink,RssTitle,RssAddress,SocAddress,SocPostalCode,SocCity,SocCountry,SocTel,Offer,Status,nbHit) VALUES (:Email,:URL,:Title,:Description,:PageRank,:Rewrite,:MetaDesc,:Origin,:BackLink,0,:RssTitle,:RssAddress,:SocAddress,:SocPostalCode,:SocCity,:SocCountry,:SocTel,:Offer,:Status,0)"); $sql->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $pageRank = new GooglePageRank($_POST["site_url"]); $sql->bindParam(":Email",$_POST["submail"],PDO::PARAM_STR); $sql->bindParam(":URL",$_POST["site_url"],PDO::PARAM_STR); $sql->bindParam(":Title",$_POST["site_title"],PDO::PARAM_STR); $sql->bindParam(":Description",$_POST["site_desc"],PDO::PARAM_STR); $sql->bindParam(":PageRank",$pageRank->PageRank,PDO::PARAM_INT); $sql->bindParam(":Rewrite",stringToRewrite($_POST["site_title"]),PDO::PARAM_STR); $sql->bindParam(":MetaDesc",$_POST["site_desc"],PDO::PARAM_STR); $sql->bindParam(":Origin",$_
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Why am I getting error SQLSTATE[HY093]: Invalid parameter number: ? How can I fix it? up vote 0 http://stackoverflow.com/questions/17027112/error-hy093-with-a-mysql-insert-pdo-request down vote favorite Based on this question How to insert array into mysql using PDO and bindParam? I'm trying to insert values of an array into mysql via PDO. I'm having a hard time of it, because I keep getting the following error. SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens for this line $stmt->execute(); I'm guessing the problem has something to do with this line $stmt->bindParam(':val$count', http://stackoverflow.com/questions/9919715/why-am-i-getting-error-sqlstatehy093-invalid-parameter-number-how-can-i-fi $val,PDO::PARAM_STR); Specifically 'val$count', but I'm not sure exactly what is going wrong. QUESTION: What am I doing wrong? How can I fix this? Anyway here is the code I'm using along with the sample array. $lastInsertValue=87; $qid[0][0]=1; $qid[0][1]=1; $qid[1][0]=2; $qid[1][1]="null"; $qid[2][0]=3; $qid[2][1]=0; $array_count = count($qid); if (isset($lastInsertValue)) { try { $dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password); $stqid=array(); $a=0; for ($i=0; $i<$array_count; $i++) { $stqid[$a]=$lastInsertValue; $a++; $stqid[$a]=$qid[$i][0]; $a++; $stqid[$a]=$qid[$i][1]; $a++; } $sql = "INSERT INTO qresults (instance, qid, result) VALUES ( :val0, :val1, :val2)"; $count = 0; $stmt = $dbh->prepare($sql); foreach ($stqid as $val) { $stmt->bindParam(':val$count', $val,PDO::PARAM_STR); $count++; } $stmt->execute(); $dbh = null; } catch(PDOException $e) { echo $e->getMessage(); } } mysql arrays pdo share|improve this question asked Mar 29 '12 at 5:46 oooooo 1,22752852 add a comment| 3 Answers 3 active oldest votes up vote 2 down vote accepted Yikes, so many issues. Your array building is so verbose. Try this $stqid = array(); foreach ($qid as $qidArr) { $stqid[] = $lastInsertValue; // no idea why you repeat this $stqid[] = $qidArr[0]; $stqid[] = $qidArr[1]; } Use positional placeholders if you're simply relying on number of arguments $sql = 'INSERT INTO ... VALUES (?, ?, ?)'; bindParam uses references which you are overwriting with each loop iteration. You would want to use bindValue() instead Y
Search Username Password Remember Me? Register Lost Password? facebook google twitter http://forums.devshed.com/php-development/942635-pdo-sqlstate-hy093-invalid-parameter-parameter-defined-post2867088.html rss Free Web Developer Tools Advanced Search https://www.experts-exchange.com/questions/27569817/PHP-MySQL-PDO-Error-PDOStatement-execute-SQLSTATE-HY093.html Forum Programming Languages PHP Development PDO: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined Thread: PDO: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined Share This Thread Tweet This + 1 this Post To invalid parameter Linkedin Subscribe to this Thread Subscribe to This Thread March 29th, 2013,09:29 PM #1 No Profile Picture etidd View Profile View Forum Posts Visit Homepage Contributing User Devshed Newbie (0 - 499 posts) Join Date May 2009 Location Atlanta, GA, invalid parameter number USA Posts 68 Rep Power 8 PDO: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined Hello all, I have been utterly stumped trying to figure out why I am getting this error about invalid parameter numbers when connecting to mySQL database. Again, the error message is as follows: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined PHP Code: for Help Receive Real-Time Help Create a Freelance Project Hire for a Full Time Job Ways to Get Help Ask a Question Ask for Help Receive Real-Time Help Create a Freelance Project Hire for a Full Time Job Ways to Get Help Expand Search Submit Close Search Login Join Today Products BackProducts Gigs Live Careers Vendor Services Groups Website Testing Store Headlines Experts Exchange > Questions > PHP MySQL PDO Error -> PDOStatement::execute(): SQLSTATE[HY093]: Want to Advertise Here? Solved PHP MySQL PDO Error -> PDOStatement::execute(): SQLSTATE[HY093]: Posted on 2012-02-03 PHP MySQL Server 1 Verified Solution 1 Comment 3,040 Views Last Modified: 2012-02-03 I've tripled checked my params and nothing seems to be out of place. I think I just need a new set of eyes because I've been at this for hours! if(isset($_POST['new_order'])) { $vendor = $_POST['vendor']; $other = $_POST['other']; $company_name = $_POST['company_name']; $load_num = $_POST['load_num']; $drop_num = $_POST['drop_num']; $cart_num = $_POST['cart_num']; $notes = $_POST['notes']; try { $DBH = new PDO('mysql:host=localhost;dbname=acsurf_ksplants', DB_USER, DB_PASSWORD); $DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); $STH = $DBH->prepare("INSERT INTO order (vendor, other_vendor, company_name, item_id, item_notes, item_qty, load_num, drop_num, cart_num, notes, date) VALUES (:vendor, :other_vendor, :company_name, :item_id, :item_notes, :item_qty, :load_num, :drop_num, :cart_num, :notes, :date)"); $STH->setFetchMode(PDO::FETCH_ASSOC); if ($Cart->hasItems()) { foreach ( $Cart->getItems() as $pid=>$quantity ) { $STH->bindParam(':vendor', $vendor); $STH->bindParam(':other_vendor', $other); $STH->bindParam(':company_name', $company_name); $STH->bindParam(':item_id', $pid); $STH->bindParam(':item_notes', $Cart->getItemNote($pid)); $STH->bindParam(':item_qty', $Cart->getItemQuantity($pid)); $STH->bindParam(':load_num', $load_num); $STH->bindParam(':drop_num', $drop_num); $STH->bindParam(':cart_num,', $cart_num); $STH->bindParam(':notes', $notes); $STH->bindParam(':date', date("Y-m-d")); $STH->execute(); } classDatabaseWriter
{
publicfunctionwriteUserToDatabase($email,$name,$age,$gender,$country,$category)
{
$host='**********';
$dbname='emailcollection';
$user