我有一个提交给自己的表单。在提交时,会生成并运行一个查询,如果 ($result) 然后我让 $success = 1 在提交电子邮件然后关闭表单的 jQuery 函数中使用。jQuery 函数取决于回显为“1”的 $success 值来触发。最近有人提交表单,生成了电子邮件,但是插入查询似乎没有向数据库中输入任何内容。
PHP代码:
require_once ('inc/dbconnect.php');
include ('inc/dataFormat.php');
if (isset($_POST['submit']) && $_POST['submit'] == 'Submit') {
$qins = sprintf('INSERT INTO becmtrack (siteName, siteNum, location, cluster, enodeName, upgDate, tech, techNum, becm, becmFail, ecm1, ecm2, ecm3, dateAlu, aluContact, aluContNum, trackNum, comment) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)', [VALUES ARE HERE]);
$rins = mysqli_query($dB, $qins) or die('Error in query => ' . $qins . '<br />' . mysqli_error($dB));
$success = ($rins) ? 1 : 0;
}
jQuery 代码(在文档就绪函数内):
if ("<? echo $success; ?>" == 1) {
var mailBody = 'Site Name: <? echo $_POST['siteName2'];?>';
mailBody += '%0ASite Number: <? echo $_POST['siteNum'];?>';
mailBody += '%0ALocation Code: <? echo $_POST['location'];?>';
mailBody += '%0AeCEMs Removed: <? echo $_POST['ecm1'] . ', ' . $_POST['ecm2'] . ', ' . $_POST['ecm3'];?>';
<? if ($_POST['dateAlu'] != '') { ?>
mailBody += '%0ADate Cards Returned to Company: <? echo $_POST['dateAlu'];?>';
mailBody += '%0AALU Contact: <? echo $_POST['aluContact'];?>';
mailBody += '%0AContact Number: <? echo $_POST['aluContNum'];?>';
mailBody += '%0AShipping Tracking Number (if applicable): <? echo $_POST['trackNum'];?>';
<? } ?>
$('#reloadTrig',window.opener.document).trigger('click');
window.open('mailto:email.address@somecompany.com?subject=eNodeB%20bCEM%20Upgrade%20Completed&body='+mailBody);
if ('<? echo $_POST['addmore'];?>' != 'addmore') {
window.close();
}
}
该代码是否可以在不将数据插入数据库的情况下生成有效结果?