我有这段代码插入一些来自一段时间,在数据库中的数据。我试图将jQuery serializearray和jQuery一起使用。但似乎我做了一些错误jQuery序列化并插入到mysql
$query= "SELECT * FROM barcode_prodotti";
$result = mysql_query($query) or die(mysql_error());
while($row=mysql_fetch_array($result)){
echo'
<input type="text" name="prodotto[]" class="prodotto" value="'.$row["prodotto"].'"></div>
<input type="text" name="prezzo[]" class="price" value="'.$row["prezzo"].'">
<input type="text" name="quantita[]" class="price" value="'.$row["quantita"].'">';
}
?>
<script src="js/mine.js"></script>
<button>Serialize form values</button>
</form>
<div id="results"></div>
这是我的jQuery代码我把mine.js
$(document).ready(function(){
$('form').submit(function(msg) {
var mia =$(this).serialize();
$('#results').text(mia)
alert($(this).serialize()); // check to show that all form data is being submitted
$.post("testtest.php",$(this).serializeArray(),function(data){
alert(data);
});
return false; });
});
这是我的PHP文件(testtest.php)
mysql_connect("localhost","root","");
mysql_select_db("db");
$arr = $_POST;
$sql="INSERT INTO table VALUES(
'".$arr['prodotto']."',
'".$arr['quantita']."',
'".$arr['prezzo']."'
)";
$rssql = mysql_query($sql);
?>
所以我序列化是好的(我试图分配一个值,看看它是否可以),但我不能在我的分贝值插入
除了使用_deprecated_ mysql函数和你的代码倾向于SQL注入,你会得到什么确切的错误或意外的结果? – user5173426
数据prodotto,prezzo和quantita不会进入名为表 – piccolopasticcio
的mysql表是否尝试'echo $ arr ['prodotto'];'并且看到你在插入之前得到了什么? – user5173426