2015-01-21 100 views
0

我幾乎擁有它,但我失去了一些東西。表單正在發送,行正在創建,但沒有數據。它是空的(電子郵件和數據庫)。我知道這是簡單的我想念但我無法弄清楚。php/ajax表單不發送信息

沒有錯誤,窗體就像它應該消失一樣。我收到一封電子郵件,但沒有用戶數據。它在數據庫中創建一行,但同樣沒有數據放在行中。

如果任何人都可以看看我的代碼,並告訴我我錯過了什麼讓輸入的信息被看到,我一定會很感激。

我已經搜索和搜索,並嘗試了不同的東西,但我不能讓它發送信息。

AJAX_Quote.php

 <?php 

    include_once('class/class_email.php'); 

    $connect = mysqli_connect("localhost","admin","password","database"); 
$FName = $_POST['Form_FName']; 
$LName = $_POST['Form_LName']; 
$Email = $_POST['Form_Email']; 
$Company = $_POST['Form_Company']; 
$Number = $_POST['Form_Number']; 
$Comments = $_POST['Form_Comments']; 
$EID = $_POST['eid']; 



    //$SQL_GetEquipment = "SELECT * FROM `new_equip` WHERE `id`='$EID' LIMIT 1;"; 
    //$R_GetEquipment = mysql_query($SQL_GetEquipment, $Link); 
    //$row = mysql_fetch_assoc($R_GetEquipment); 
    $SQL_GetEquipment = "SELECT * FROM `new_equip` WHERE `id`='$EID' LIMIT 1;"; 
    $result = mysqli_query($connect,$SQL_GetEquipment); 
    $row = mysqli_fetch_assoc($result); 
    $EmailBody = "$FName $LName has requested a quote from NAPE on Item $EID\n 

    Information on quote request: \n 
    Name: $FName $LName \n 
    Email: $Email \n 
    Company: $Company \n 
    Number: $Number \n 
    Comments: $Comments \n 
    \n 
    Information Requested for: {$row['itemname']}\n 
    The URL to {$row['itemname']} is: http://www.domain.com/new-product.php?Item=$EID 
    \n 
    Click to send a quote now:\n 
    http://www.domain.com/Admin/send-quote.php?id=$EID "; 

    $e = new email(); 

    //First value is the URL of your server, the second the port number 
    $e->set_server('mail.domain.com', 26); 

    //First value is your username, then your password 
    $e->set_auth('[email protected]', 'nape112233'); 

    //Set the "From" setting for your e-mail. The Name will be base64 encoded 
    $e->set_sender('Quote Requested', '[email protected]'); 

    //for one recipient 
    $send_to = array('[email protected]'); 
    //you may also specify multiple recipients by creating an array like this: 
    //$send_to = array('[email protected]', '[email protected]', '[email protected]'); 

    $subject = 'Quote Request from NAPE'; 
    $body = "$EmailBody"; 
    if($e->mail($send_to, $subject, $body, $headers) == true) 
    { 
     //message was received by the smtp server 
     //['last'] tends to contain the queue id so I like to save that string in the database 
     echo 'last: '.htmlspecialchars($e->srv_ret['last']).''; 
    }else{ 
     //something went wrong 
     echo 'all: '.nl2br(htmlspecialchars($e->srv_ret['all'])).''; 
     echo 'full:'.nl2br(htmlspecialchars($e->srv_ret['full'])).''; 
    } 
    mysqli_query($connect,"INSERT INTO users (`fname`,`lname`,`email`,`company`,`number`) 
    VALUES ('$FName','$LName','$Email','$Company','$Number')"); 

    ?> 

我的表單代碼

<form id="contact" name="contact" action="#" method="post" style="width:600px"> 
     <br /> 
     <table width="80%"> 
      <tr> 
       <td width="36%">*First Name:</td> 
       <td width="3%">&nbsp;</td> 
       <td width="61%"> 
        <input type="text" id="Form_FName" name="Form_FName" /> 
       </td> 
      </tr> 
      <tr> 
       <td width="36%">*Last Name:</td> 
       <td width="3%">&nbsp;</td> 
       <td width="61%"> 
        <input type="text" id="Form_LName" name="Form_LName" /> 
       </td> 
      </tr> 
      <tr> 
       <td width="36%">Company Name:</td> 
       <td width="3%">&nbsp;</td> 
       <td width="61%"> 
        <input type="text" id="Form_Company" name="Form_Company" /> 
       </td> 
      </tr> 

      <tr> 
       <td>*Your E-Mail:</td> 
       <td>&nbsp;</td> 
       <td> 
        <input type="text" id="Form_Email" name="Form_Email" /> 
       </td> 
      </tr> 
      <tr> 
       <td width="36%">*Phone Number:</td> 
       <td width="3%">&nbsp;</td> 
       <td width="61%"> 
        <input type="text" id="Form_Number" name="Form_Number" /> 
       </td> 
      </tr> 
      <tr> 
       <td width="36%" h>Comments:</td> 
       <td width="3%">&nbsp;</td> 
       <td width="61%"> 
        <textarea id="Form_Comments" name="Form_Comments" cols="25" rows="3"></textarea> 
       </td> 
      </tr> 
      <tr> 
       <td colspan="3">&nbsp;</td> 
      </tr> 
      <tr> 
       <td width="36%" align="center" colspan="3"> 
        <button id="send">Request Quote</button> 
       </td> 
      </tr> 
      <tr> 
       <td colspan="5">&nbsp;</td> 
      </tr> 
      <tr> 
       <td width="100%" colospan="3"> 
        <b><?php echo $itemname; ?></b> 
        <br /> 
        <br /> Manufacturer: <?php echo $manufactuer;?> 
        <br /> Model: <?php echo $model;?> 
        <br /> Category: <?php echo $category;?> 
        <br /> 
       </td> 
      </tr> 
     </table> 
    </form> 
</div> 

<!-- basic fancybox setup --> 
<script type="text/javascript"> 
    $(document) 
     .ready(function() { 
      $(".modalbox").fancybox(); 
      $("#contact").submit(function() { 
        return false; 
       }); 
      $("#send").on("click", function() { 

        { 
         // if both validate we attempt to send the e-mail 
         // first we hide the submit btn so the user doesnt click twice 
         $("#send").replaceWith("<em>Your request has been sent...</em>"); 

         $.ajax({ 
          type: "POST", 
          url: "AJAX_Quote.php", 
          data: $("#idForm").serialize(),         
          success: setTimeout(function() { parent.$.fancybox.close(); }, 2000) 


         }); 
        } 
       }); 
     }); 
</script> 
+0

你期望的結果是什麼?你會得到什麼結果? 「表單不發送信息」不是很具描述性。你的代碼出錯了嗎?它發送郵件嗎?你的查詢結果是什麼? '$ _POST'看起來像什麼?你獲得ajax請求的返回碼是什麼? – chiliNUT 2015-01-21 02:47:36

+1

對不起,我想我已經盡我所能解釋了它。我是新來的PHP。沒有錯誤,窗體就像它應該消失一樣。我收到一封電子郵件,但沒有用戶數據。它在數據庫中創建一行,但同樣沒有數據放在行中。 – WebbieWorks 2015-01-21 02:55:47

+0

啊,沒問題。歡迎來到堆棧溢出!任何好問題的一個重要質量就是清楚地描述你得到的結果與你期望的結果。你應該在問題中包含這些信息。 – chiliNUT 2015-01-21 02:59:09

回答

3

的表單輸入的名稱是格式name="Form_FName"的,但在你的PHP,你把它們稱爲$FName = $_POST['fname'];。正確的PHP將是$FName = $_POST['Form_FName'];

此外我建議轉義您的輸入字段,以避免SQL注入。檢查mysqli_real_escape_string。

http://php.net/manual/en/mysqli.real-escape-string.php

+0

我改變了php,但是電子郵件仍然沒有值。 – WebbieWorks 2015-01-21 03:05:16

+0

而不是把數據轉換成JSON,從你的JS中刪除你當前的數據和數據類型,並替換它們:'data:$(「#contact」)。serialize(),',再次確保輸入字段名稱匹配它們的$ _POST [''] ID在PHP中。 – 2015-01-21 03:15:32

+0

我很感激,我替換了代碼。儘管如此,我仍然是空白。我編輯我原來的帖子與更新的代碼。 – WebbieWorks 2015-01-21 03:19:31