脚本宝典收集整理的这篇文章主要介绍了php – PDO bindValue适用于其他输入,为什么不这个?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
echo "<form id=changerform name=changerform action=updatesubmIT.PHP method=post>"; echo "<span id=titleBox>Title: <input class=attributefield style='border:none' tyPE=text size=100 id=Title value='".$item['Title']."' />Change This?</span> <br>"; echo "<span id=authorBox>Author: <input class=attributefield style='border:none' type=text id=Author value='".$item['Author']."' />Change This?</span><br>"; echo "<span id=description>Description: <textarea class=attributefield style='border:none' rows=9 cols=100 name=Description id=Description >".$item['Description']."</textarea></span>"; echo "<input type='hidden' id='BookiDField' name='bookidfield' value = '".$tochange."' />";
这个表单由一些看起来像这样的PHP处理:
while($Nowfield = current($_POST)){ $col = key($_POST); switch($col){ case 'Title': $qstring = 'UPDATE Mainbooks SET Title = :slug WHERE ItemID LIKE :bookid;'; break; case 'Author': $qstring = 'UPDATE Mainbooks SET Author = :slug WHERE ItemID LIKE :bookid;'; break; case 'Description': $qstring = "UPDATE Mainbooks SET Description = :slug WHERE ItemID LIKE :bookid;"; break; default: echo "Invalid input"; break; }//end switch $upquery = $safelink->PRepare($qstring); $upquery->bindValue(':slug',$Nowfield,PDO::PARAM_STR); $upquery->bindValue(':bookid',$_POST['bookidfield'],PDO::PARAM_INT); $upquery->execute(); next($_POST); } //end while
我把它组织成一个switch语句,因为表单中的代码只传递已在Post中更改过的字段(除了’bookidfield’输入,其中包含每个项目的唯一键.)交换机,只运行必要的查询.
“标题”和“作者”字段工作正常;他们更新没有问题的新值.但是,“描述”字段始终更新为“bookidfield”的值.我可以修复它,如果我进去并手动将’:bookid’参数更改为我想要的书的id.
如果我var_dump(_ $POST)它似乎通过正确的键值,如下所示:
array(4) { ["Title"]=> string(22) "Gross Boogers and Such" ["Author"]=> string(14) "Franny Panties" ["Description"]=> string(55) "This is the value I want to change the description to!!" ["bookidfield"]=> string(3) "184" }
但是在我的sql表中,它会将书184的标题改为“Gross Boogers and Such”,将作者改为“Franny Panties”,但它会将描述改为“184”.它与我使用bindValue()有关,对吧?或者它与我的循环有关?这是表格的名称吗?我一直在看它太长时间看不出它是什么.
感谢Stackoverflow,你们很棒.
以上是脚本宝典为你收集整理的php – PDO bindValue适用于其他输入,为什么不这个?全部内容,希望文章能够帮你解决php – PDO bindValue适用于其他输入,为什么不这个?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。