2017-04-08 1 views
0

HII人はウェブプログラミングとイムこのウェブサイトでは、ウェブサイト を作成する新しいイムフォームを送信すると、私たちはこのあなたが

<form action="footer_contactus1.php" method="post"> 
    <div class="row"> 
    <div class="form-grope col-lg-4"> 
     <label><span class="glyphicon glyphicon-user"></span>Name</label><br> 
     <input name="cuname" type="text" class="form-cotrol"> 
    </div> 
    <div class="form-grope col-lg-4"> 
     <label><samp class="glyphicon glyphicon-envelope"></samp>Email</label><br> 
     <input name="cuemail" type="email" class="form-cotrol"> 
    </div> 
    <div class="form-grope col-lg-4"> 
     <label><i class="glyphicon glyphicon-earphone"></i>Phone Number</label><br> 
     <input name="cutele" type="tel" class="form-cotrol"> 
    </div> 

    <div class="form-grope col-lg-12"> 
    <br> 
     <label><span class="glyphicon glyphicon-paste"></span>Message</label><br> 
     <textarea name="cumessage" class="form-cotrol" rows="6" style="width: 100%;" ></textarea> 
    </div> 
    <div class="form-grope col-lg-12"> 
    <br> 
     <input type="hidden" name="save" value="contact"> 
     <button type="submit" class="btn btn-info">Submit</button> 
    </div> 
    </div> 
</form> 
のようなページのフッターに形成する連絡先を追加したいページを更新していけません

と私は入力が

<?php 

$pdo = new PDO('mysql:host=localhost;dbname=mywsite_db', 'root', ''); 

$req = $pdo->prepare('INSERT INTO message (id_message,nom,email,tele,message) 
VALUES(null,?,?,?,?)'); 
$req->execute(array($_POST['cuname'],$_POST['cuemail'],$_POST['cutele'],$_POST['cumessage'])); 

header('Location: HomePage.php'); 

?> 

データベース にPHPファイルを挿入してしまったので、実行を取得するために私はPHPファイルをしたい[送信]ボタンをクリックしたときに、私は、このフォームはAJAXでページを更新せずにsubmited取得したい 私は別のチュートリアルを試してみましたが、何もできませんでしたplzzは私のフォーム用の正しいajaxスクリプトを提供するので、PHPファイルに提出してデータベースにデータを挿入してから、メッセージ(警告)ページplzzを更新せずにインダーしています

答えて

1
<form action="footer_contactus1.php" method="post" id="myForm1"> 
    ... 
</form> 

<script type="text/javascript"> 
    var frm = $('#myForm1'); 
    frm.submit(function (ev) { 
     $.ajax({ 
      type: frm.attr('method'), 
      url: frm.attr('action'), 
      data: frm.serialize(), 
      success: function (data) { 
       alert('The data has been inserted'); 
      } 
     }); 

     ev.preventDefault(); 
    }); 
</script> 
+0

あなたは人生の節約になりました –

関連する問題