脚本宝典收集整理的这篇文章主要介绍了php – MYSQL – INSERT错误,字段列表中的未知列,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
require_once("connect.PHP"); $query = MysqL_query("SELECT * From accounts ORDER BY id DESC LIMIT 1"); $row = MysqL_fetch_assoc($query); $balanceold = $row['balance']; $difference = $_POST['predec'].".".$_POST['dec']; $category = $_POST['category']; $notes = $_POST['notes']; if(isset($_POST['in'])){ $balancenew = $balanceold + $difference; $query = MysqL_query("INSERT INTO accounts(currentbalance,balancein,category,notes) VALUES (".$balancenew.",".$difference.",".$category.",".$notes.")"); if($query){ header("Location: budget.PHP"); } else{ die(MysqL_error()); } }
给出错误:
“字段列表”中的未知列“发薪日”
这是我的表单代码:
<form action=PRocess.PHP method=post> &pound; <input tyPE=text name=predec size=7> . <input type=text name=dec size=4 value=00> <br /> <select name=category> <option value=payday>Payday</option> </select> <input type=text name=notes size=20> <input type=submit name=in value=Deposit> <input type=submit name=out value=Withdraw> </form>
数据库表“accounts”包含以下字段:
id,int Primary A_I
balancein,十进制10,2
平衡,2
当前余额,2
category,vArchar 50
notes,VARchar 255
日期,时间戳
…以该顺序
MysqL_query("INSERT INTO accounts(currentbalance,notes) VALUES ('$balancenew','$difference','$category','$notes')");
最好使用mysqli或PDO来防止sql注入攻击,你现在可以使用MysqL_real_escape_string():
$balancenew = MysqL_real_escape_string($balancenew);
以及其他变量.
以上是脚本宝典为你收集整理的php – MYSQL – INSERT错误,字段列表中的未知列全部内容,希望文章能够帮你解决php – MYSQL – INSERT错误,字段列表中的未知列所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。