I have a form that submits to itself. On submit, a query is generated and run and if ($result) then I make $success = 1 to use in a jQuery function that submits an email and then closes the form. The jQuery function is dependent on the $success value echoed being '1' to trigger. Recently I had someone submit the form, the email was generated, but the insert query did not appear to enter anything into the database.
The PHP code:
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;
}
The jQuery code (inside a document ready function):
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();
}
}
Is there someway for this code to generate a valid result without the data being inserted into the database?