2015-01-21 85 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