我尝试从html插入到mysql(Phonegap)。但他不这样做......我的错误是什么?为了帮助我,我感到很糟糕 我有 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ HTML:
script
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~ Post.js
<div id="landmark-1" data-landmark-id="1">
<form>
<div id="block1">Datum:<input type="date" id="date" name="date"></div>
<div id="block2">Baustelle: <input name="bau" id="bau" class="tb1" type="text" size="18" /></div>
<div id="block4">
<input type="submit" value="Speichern">
</div>
</form>
</div>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~ PHP:
$(document).bind('deviceready', function(){
$(function(){
$('form').submit(function(){
var landmarkID = $(this).parent().attr('data-landmark-id');
var postData = $(this).serialize();
alert(postData+'&lid='+landmarkID);
$.ajax({
type: 'POST',
data: postData+'&lid='+landmarkID,
//change the url for your project
url: "http://voss-hm.de/zeitserver/save.php",
success: function(data){
console.log(data);
alert('Your comment was successfully added');
},
error: function(){
console.log(data);
alert('There was an error adding your comment');
}
});
return false;
});
});
});
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~
答案 0 :(得分:0)
$_POST
而非$_Post
mysql_
- 功能!请改用mysqli_
或PDO。答案 1 :(得分:0)
这里有一些错误。
首先,使用$ _POST代替$ _Post(案例事项)。
其次,你不应该再使用mysql_ *函数了。请阅读本教程:https://www.binpress.com/tutorial/using-php-with-mysql-the-right-way/17
你的脚本现在很容易受到很多攻击,你真的需要学会逃避POST值。如果您在发布的值中有单引号,那么您的脚本也将无效。下面的链接将教你如何处理这个问题。
从PHP脚本返回JSON编码的对象也是一个好主意。