我几乎拥有它,但我遗失了一些东西。表单正在发送并且正在创建行但没有数据。它是空白的(电子邮件和数据库)。我知道这是一件很简单的事情,但我无法弄明白。
没有错误,表单会像预期的那样消失。我收到了一封电子邮件,但其中没有用户数据。它在数据库中创建了一行,但同样没有数据放入该行。
如果有人可以查看我下面的代码并告诉我我缺少什么来查看输入的信息,我一定会很感激。
我搜索并搜索并尝试了不同的东西,但我无法发送信息。
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('noreply@domain.com', 'nape112233');
//Set the "From" setting for your e-mail. The Name will be base64 encoded
$e->set_sender( 'Quote Requested', 'noreply@domain.com' );
//for one recipient
$send_to = array('email@gmail.com');
//you may also specify multiple recipients by creating an array like this:
//$send_to = array('foo1@localhost.local', 'foo2@localhost.local', 'foo3@localhost.local');
$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%"> </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%"> </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%"> </td>
<td width="61%">
<input type="text" id="Form_Company" name="Form_Company" />
</td>
</tr>
<tr>
<td>*Your E-Mail:</td>
<td> </td>
<td>
<input type="text" id="Form_Email" name="Form_Email" />
</td>
</tr>
<tr>
<td width="36%">*Phone Number:</td>
<td width="3%"> </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%"> </td>
<td width="61%">
<textarea id="Form_Comments" name="Form_Comments" cols="25" rows="3"></textarea>
</td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td width="36%" align="center" colspan="3">
<button id="send">Request Quote</button>
</td>
</tr>
<tr>
<td colspan="5"> </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 :(得分:3)
表单输入的名称格式为name="Form_FName"
,但在PHP中,您将其称为$FName = $_POST['fname'];
。正确的PHP将是$FName = $_POST['Form_FName'];
另外,我建议转义输入字段以避免SQL注入。查看mysqli_real_escape_string。