2017-02-03 8 views
0

私はすでにこれについていくつかの質問をしましたが、助けられましたが、フォームが正常で、 "ここに何か"私のフォームは、入力 "テキスト"名前 "テーブル"を置くだけですフォームの残りの部分は、mysqlのajaxを経由しています。私の質問は、動的なので、このフォームをデータベースに渡すにはどうすればいいですか?下の私のコード。動的フォームとjqueryとajaxを経由してmysqlに送信

マイフォーム

<div class="well"> 


       <!-- left --> 
       <div id="theproducts" class="col-sm-5"> 
       </div> 
       <!-- left --> 
       <form method="post" action="relatorio.php" id="formRel"> 
       <span>Mesa</span> 
     <input type="text" id="numero_mesa" name="numero_mesa"> 
       <input type="text" id="theinputsum"> 

       <!-- right --> 
       <div id="thetotal" class="col-sm-7"> 
        <h1 id="total"></h1> 
        <button type="submit" class="btn btn-lg btn-success btn-block"><i class="fa fa-shopping-cart" aria-hidden="true"></i> Finalizar Pedido</button> 
       </form> 
       </div> 
       <!-- right --> 


      </div> 

とJavaScriptコード。

<script> 
$('#formRel').submit(function(event){ 
     event.preventDefault(); 
     var formDados = new FormData($(this)[0]); 
$.ajax({ 
    method: "POST", 
    url: "relatorio.php", 
    data: $("#formRel").serialize(), 
    dataType : "html" 
}) 
}; 
</script> 

挿入クエリは次のとおりです。

<?php 
error_reporting(-1); 
ini_set('display_errors', 'On'); 


//Criar a conexao 
$link = new mysqli ("localhost", "root", "", "restaurant"); 
if($link->connect_errno){ 
    echo"Nossas falhas local experiência .."; 
    exit(); 
} 
//echo "<pre>"; print_r($_POST); exit; 
$mesa = $_POST['numero_mesa']; 
$pedido = $_POST['products']; 
$preco = $_POST['products']; 


$sql = "INSERT INTO spedido ('pedido','preco','numero_mesa') VALUES ('$mesa','$pedido','$preco')"; 

$link->query($sql); 





?> 

enter image description here

答えて

0
<script> 
$(document).on('submit', '#formRel', function(event) { 
    event.preventDefault(); 
    var numero_mesa = $('#numero_mesa').val(); 
    $.ajax({ 
     type: "POST", 
     url: "relatorio.php?", 
     data: "numero_mesa="+ numero_mesa+ 
     "&products="+ products, 
     success: function (data) { 
      alert(data) // this will send you a message that might help you see whats going on in your php file 
     }); 
    }) 
}; 
</script> 
+0

しかし、どのように私は、MySQLに送信するんです、データベースに送信し、私はPHPで一部を行うことができますどのようにタイプ? –

関連する問題