いくつかの入力があるフォームを作成しました。これらの入力のいずれかを入力すると、mysql に新しい行が挿入されます。しかし、新しい fielddate ごとに sql を更新したい場合、データを mysql に送信する方法がわからないため、失われます。
ここに私のスクリプトがあります:
<script>
Here I check and post a row to sql if this is the first keyup.
$('.ajax').keyup(function(){
if(document.getElementById("id").value==0){
$.ajax({
type:'get',
data: { insert: "1" },
url:location.href,
dataType:'json',
success:function(response){
var id = response.id;
if(typeof(id) != 'undefined'){
$('#id').val(id);
}
}
});
document.getElementById("id").value="1";
$("#rejtett1").show();
$("#rejtett2").show();
$("#rejtett3").show();
}
else{
If not, here I post the form!
$('#addfelhasznalo').delay(200).submit();
}
});
There I want to update the data to mysql.
$("#addfelhasznalo").submit(function (event) {
event.preventDefault();
$.ajax({
type: "get",
dataType: "json",
url: location.href+"?update=1",
data: $("#addfelhasznalo").serialize(),
success: function (response) {
}
});
});
</script>
if($_GET["insert"]){
mysql_query("INSERT into accounts() VALUES()");
}
if($_GET["update"]){
mysql_query("UPDATE accounts SET ".$_GET["field"]."=".$_GET["fielddata"]." WHERE id='".$_GET["id"]."'");
}