Jump to content

[SOLVED] Check ID and return error if already exists


goldenbrown21

Recommended Posts

Hi Fellow-PHPers,

 

I'm developing a database which allows employees of a company enter details of their customers.

 

At the moment, when a user inputs customer details to be added into the database, the form values go to a script (called input.php), which validates that certain fields are completed. If not, an error is presented to the user indicating that they need to fill that field in. Alternatively, if the required information is presented, then the information is inserted into the MYSQL database.

 

This is working... however, if the user inputs data where the primary key (called custcode) already exists, the script shows an error which indicates that that the "StreetAddress" is not filled, not the "custcode error". The streetaddress error is actually the second field check in my script.

 

Can someone advise me how to change my script so that when this instance occurs, the correct error is actually displayed ("CustomoerCode already exists")?

<?PHP
$sessCustCode = $HTTP_POST_VARS['CustCode'];
$sessCustName = $HTTP_POST_VARS['CustName'];
$sessStreetAddress = $HTTP_POST_VARS['StreetAddress'];
$sessPostcode = $HTTP_POST_VARS['Postcode'];
$sessEmail = $HTTP_POST_VARS['Email'];
$sessTelephone = $HTTP_POST_VARS['Telephone'];
$sessFAX = $HTTP_POST_VARS['FAX'];
$sesstdr = $HTTP_POST_VARS['tdr'];
$sessNotes = $HTTP_POST_VARS['Notes'];
$sessMTD = $HTTP_POST_VARS['MTD'];
$sessLastMonth = $HTTP_POST_VARS['LastMonth'];
$sessLast3Months = $HTTP_POST_VARS['Last3Months'];
$sessYTD = $HTTP_POST_VARS['YTD'];
$sessDate = $HTTP_POST_VARS['Date'];
$sessCallout = $HTTP_POST_VARS['Callout'];


define('kOptional', true);
define('kMandatory', false);

define('kStringRangeFrom', 1);
define('kStringRangeTo', 2);
define('kStringRangeBetween', 3);
        
define('kYes', 'yes');
define('kNo', 'no');

error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('track_errors', true);

function DoStripSlashes($fieldValue)  { 
if ( get_magic_quotes_gpc() ) { 
  if (is_array($fieldValue) ) { 
   return array_map('DoStripSlashes', $fieldValue); 
  } else { 
   return stripslashes($fieldValue); 
  } 
} else { 
  return $fieldValue; 
} 
}

function FilterCChars($theString) {
return preg_replace('/[\x00-\x1F]/', '', $theString);
}

function ProcessPHPFile($PHPFile) {
ob_start();
require $PHPFile;
return ob_get_clean();
}

function CheckString($value, $low, $high, $mode, $limitAlpha, $limitNumbers, $limitEmptySpaces, $limitExtraChars, $optional) {
if ($limitAlpha == kYes) {
  $regExp = 'A-Za-z';
}

if ($limitNumbers == kYes) {
  $regExp .= '0-9'; 
}

if ($limitEmptySpaces == kYes) {
  $regExp .= ' '; 
}

if (strlen($limitExtraChars) > 0) {

  $search = array('\\', '[', ']', '-', '$', '.', '*', '(', ')', '?', '+', '^', '{', '}', '|');
  $replace = array('\\\\', '\[', '\]', '\-', '\$', '\.', '\*', '\(', '\)', '\?', '\+', '\^', '\{', '\}', '\|');

  $regExp .= str_replace($search, $replace, $limitExtraChars);

}

if ( (strlen($regExp) > 0) && (strlen($value) > 0) ){
  if (preg_match('/[^' . $regExp . ']/', $value)) {
   return false;
  }
}

if ( (strlen($value) == 0) && ($optional === kOptional) ) {
  return true;
} elseif ( (strlen($value) >= $low) && ($mode == kStringRangeFrom) ) {
  return true;
} elseif ( (strlen($value) <= $high) && ($mode == kStringRangeTo) ) {
  return true;
} elseif ( (strlen($value) >= $low) && (strlen($value) <= $high) && ($mode == kStringRangeBetween) ) {
  return true;
} else {
  return false;
}

}


function CheckEmail($email, $optional) {
if ( (strlen($email) == 0) && ($optional === kOptional) ) {
  return true;
} elseif ( eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email) ) {
  return true;
} else {
  return false;
}
}



if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$clientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$clientIP = $_SERVER['REMOTE_ADDR'];
}

$FTGCustCode = DoStripSlashes( $_REQUEST['CustCode'] );
$FTGCustName = DoStripSlashes( $_REQUEST['CustName'] );
$FTGStreetAddress = DoStripSlashes( $_REQUEST['StreetAddress'] );
$FTGSuburb = DoStripSlashes( $_REQUEST['Suburb'] );
$FTGState = DoStripSlashes( $_REQUEST['State'] );
$FTGTradingPattern = DoStripSlashes( $_REQUEST['TradingPattern'] );
$FTGMTD = DoStripSlashes( $_REQUEST['MTD'] );
$FTGPaymentType = DoStripSlashes( $_REQUEST['PaymentType'] );
$FTGLastMonth = DoStripSlashes( $_REQUEST['LastMonth'] );
$FTGBusinessType = DoStripSlashes( $_REQUEST['BusinessType'] );
$FTGLast3Months = DoStripSlashes( $_REQUEST['Last3Months'] );
$FTGPreferredShippingMethod = DoStripSlashes( $_REQUEST['PreferredShippingMethod'] );
$FTGYTD = DoStripSlashes( $_REQUEST['YTD'] );
$FTGPostcode = DoStripSlashes( $_REQUEST['Postcode'] );
$FTGEmail = DoStripSlashes( $_REQUEST['Email'] );
$FTGTelephone = DoStripSlashes( $_REQUEST['Telephone'] );
$FTGFAX = DoStripSlashes( $_REQUEST['FAX'] );
$FTGtdr = DoStripSlashes( $_REQUEST['tdr'] );
$FTGNotes = DoStripSlashes( $_REQUEST['Notes'] );
$FTGProductFocus = DoStripSlashes( $_REQUEST['ProductFocus'] );
$FTGNewCustomer = DoStripSlashes( $_REQUEST['NewCustomer'] );
$FTGOem = DoStripSlashes( $_REQUEST['Oem'] );
$FTGSystem = DoStripSlashes( $_REQUEST['System'] );
$FTGPeripherals = DoStripSlashes( $_REQUEST['Peripherals'] );
$FTGConsumables = DoStripSlashes( $_REQUEST['Consumables'] );
$FTGTelecommunications = DoStripSlashes( $_REQUEST['Telecommunications'] );
$FTGOther = DoStripSlashes( $_REQUEST['Other'] );
$FTGInput = DoStripSlashes( $_REQUEST['Input'] );
$FTGDate = DoStripSlashes( $_REQUEST['Date'] );
$FTGCallout = DoStripSlashes( $_REQUEST['Callout'] );
$FTGingram = DoStripSlashes( $_REQUEST['ingram'] );
$FTGcellnet = DoStripSlashes( $_REQUEST['cellnet'] );
$FTGaltech = DoStripSlashes( $_REQUEST['altech'] );
$FTGachieva = DoStripSlashes( $_REQUEST['achieva'] );
$FTGalloys = DoStripSlashes( $_REQUEST['alloys'] );
$FTGbrightpoint = DoStripSlashes( $_REQUEST['brightpoint'] );
$FTGdicker = DoStripSlashes( $_REQUEST['dicker'] );
$FTGexpress = DoStripSlashes( $_REQUEST['express'] );
$FTGsimms = DoStripSlashes( $_REQUEST['simms'] );
$FTGtoday = DoStripSlashes( $_REQUEST['today'] );
$FTGwestan = DoStripSlashes( $_REQUEST['westan'] );
$FTGdists = DoStripSlashes( $_REQUEST['dists'] );

# Fields Validations
        
$validationFailed = false;
if (!CheckString($FTGCustCode, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) {
$FTGErrorMessage['CustCode'] = 'Cusomercode already exists or entered incorrectly';
$validationFailed = true;
}

if (!CheckString($FTGCustName, 3, 25, kStringRangeBetween, kNo, kNo, kNo, '', kMandatory)) {
$FTGErrorMessage['CustName'] = 'Please enter customer/business name';
$validationFailed = true;
}

if (!CheckString($FTGStreetAddress, 3, 25, kStringRangeBetween, kNo, kNo, kNo, '', kMandatory)) {
$FTGErrorMessage['StreetAddress'] = 'Please enter street address';
$validationFailed = true;
}

if (!CheckString($FTGSuburb, 3, 25, kStringRangeBetween, kNo, kNo, kNo, '', kMandatory)) {
$FTGErrorMessage['Suburb'] = 'Please enter suburb';
$validationFailed = true;
}

if (!CheckString($FTGPostcode, 4, 4, kStringRangeBetween, kNo, kYes, kNo, '', kMandatory)) {
$FTGErrorMessage['Postcode'] = 'Please enter postcode';
$validationFailed = true;
}

if (!CheckEmail($FTGEmail, kMandatory)) {
$FTGErrorMessage['Email'] = 'Please enter valid email address';
$validationFailed = true;
}

if (!CheckString($FTGTelephone, 10, 15, kStringRangeBetween, kNo, kNo, kNo, '', kMandatory)) {
$FTGErrorMessage['Telephone'] = 'Please enter telephone number';
$validationFailed = true;
}

if (!CheckString($FTGtdr, 3, 10, kStringRangeBetween, kNo, kNo, kNo, '', kMandatory)) {
$FTGErrorMessage['tdr'] = 'Please enter TDR or area allocation';
$validationFailed = true;
}



# Include message in error page and dump it to the browser

if ($validationFailed === true) {

$errorPage = '<html><head><title>Error</title></head>
<body><p align="center"> </p><p align="center"> </p><p align="center"> </p>
<p align="center"> Customer was not added due to the following errors found:</p> <p align="center"> </p><p class="style1" align="center"><!--VALIDATIONERROR--></p>
<p align="center"> </p><p align="center"> </p>
<p align="center"><strong>Please hit the back button on your browser and amend the details</strong></p></body></html>';

$errorPage = str_replace('<!--FIELDVALUE:CustCode-->', $FTGCustCode, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:CustName-->', $FTGCustName, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:StreetAddress-->', $FTGStreetAddress, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:Suburb-->', $FTGSuburb, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:State-->', $FTGState, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:TradingPattern-->', $FTGTradingPattern, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:MTD-->', $FTGMTD, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:PaymentType-->', $FTGPaymentType, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:LastMonth-->', $FTGLastMonth, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:BusinessType-->', $FTGBusinessType, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:Last3Months-->', $FTGLast3Months, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:PreferredShippingMethod-->', $FTGPreferredShippingMethod, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:YTD-->', $FTGYTD, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:Postcode-->', $FTGPostcode, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:Email-->', $FTGEmail, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:Telephone-->', $FTGTelephone, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:FAX-->', $FTGFAX, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:tdr-->', $FTGtdr, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:Notes-->', $FTGNotes, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:ProductFocus-->', $FTGProductFocus, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:NewCustomer-->', $FTGNewCustomer, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:Oem-->', $FTGOem, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:System-->', $FTGSystem, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:Peripherals-->', $FTGPeripherals, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:Consumables-->', $FTGConsumables, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:Telecommunications-->', $FTGTelecommunications, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:Other-->', $FTGOther, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:Input-->', $FTGInput, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:Date-->', $FTGDate, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:Callout-->', $FTGCallout, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:ingram-->', $FTGingram, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:cellnet-->', $FTGcellnet, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:achieva-->', $FTGachieva, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:simms-->', $FTGsimms, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:today-->', $FTGtoday, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:alloys-->', $FTGalloys, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:altech-->', $FTGaltech, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:brightpoint-->', $FTGbrightpoint, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:dicker-->', $FTGdicker, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:express-->', $FTGexpress, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:westan-->', $FTGwestan, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:dists-->', $FTGdists, $errorPage);
$errorPage = str_replace('<!--ERRORMSG:CustCode-->', $FTGErrorMessage['CustCode'], $errorPage);
$errorPage = str_replace('<!--ERRORMSG:CustName-->', $FTGErrorMessage['CustName'], $errorPage);
$errorPage = str_replace('<!--ERRORMSG:StreetAddress-->', $FTGErrorMessage['StreetAddress'], $errorPage);
$errorPage = str_replace('<!--ERRORMSG:Suburb-->', $FTGErrorMessage['Suburb'], $errorPage);
$errorPage = str_replace('<!--ERRORMSG:Postcode-->', $FTGErrorMessage['Postcode'], $errorPage);
$errorPage = str_replace('<!--ERRORMSG:Email-->', $FTGErrorMessage['Email'], $errorPage);
$errorPage = str_replace('<!--ERRORMSG:Telephone-->', $FTGErrorMessage['Telephone'], $errorPage);
$errorPage = str_replace('<!--ERRORMSG:tdr-->', $FTGErrorMessage['tdr'], $errorPage);


$errorList = implode("<br />\n",  $FTGErrorMessage);
$errorPage = str_replace('<!--VALIDATIONERROR-->', $errorList, $errorPage);

echo $errorPage;
exit;

}
#====================================================
# Dump field values to a MySQL table                =
#====================================================

$mysqlLink = @mysql_connect("localhost", "login", "password");


if (mysql_errno() == 0) {

@mysql_select_db("database", $mysqlLink);


}

if (mysql_errno() == 0) {

  $sqlCmd = sprintf("INSERT INTO customerdetails(custcode, custname, `Street Address`, Suburb, `State`, `Trading Pattern`, MTD, `Payment Type`, `Last Month`, `Business Type`, `Last 3 Months`, `Preferred Shipping Method`, `YTD`, `PostCode`, `Email`, `Telephone`, `FAX`, `TDR`, `Notes`, `Product Focus`, newcustomer, OEM, System, Peripherals, Consumables, Telecommunications, ingram, cellnet, altech, achieva, alloys, brightpoint, dicker, express, simms, today, westan, dists, Other) VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
                   mysql_real_escape_string($FTGCustCode, $mysqlLink),
                   mysql_real_escape_string($FTGCustName, $mysqlLink),
                   mysql_real_escape_string($FTGStreetAddress, $mysqlLink),
                   mysql_real_escape_string($FTGSuburb, $mysqlLink),
                   mysql_real_escape_string($FTGState, $mysqlLink),
                   mysql_real_escape_string($FTGTradingPattern, $mysqlLink),
                   mysql_real_escape_string($FTGMTD, $mysqlLink),
                   mysql_real_escape_string($FTGPaymentType, $mysqlLink),
                   mysql_real_escape_string($FTGLastMonth, $mysqlLink),
                   mysql_real_escape_string($FTGBusinessType, $mysqlLink),
                   mysql_real_escape_string($FTGLast3Months, $mysqlLink),
                   mysql_real_escape_string($FTGPreferredShippingMethod, $mysqlLink),
                   mysql_real_escape_string($FTGYTD, $mysqlLink),
                   mysql_real_escape_string($FTGPostcode, $mysqlLink),
                   mysql_real_escape_string($FTGEmail, $mysqlLink),
                   mysql_real_escape_string($FTGTelephone, $mysqlLink),
                   mysql_real_escape_string($FTGFAX, $mysqlLink),
                   mysql_real_escape_string($FTGtdr, $mysqlLink),
                   mysql_real_escape_string($FTGNotes, $mysqlLink),
                   mysql_real_escape_string($FTGProductFocus, $mysqlLink),
                   mysql_real_escape_string($FTGNewCustomer, $mysqlLink),
                   mysql_real_escape_string($FTGOem, $mysqlLink),
                   mysql_real_escape_string($FTGSystem, $mysqlLink),
                   mysql_real_escape_string($FTGPeripherals, $mysqlLink),
                   mysql_real_escape_string($FTGConsumables, $mysqlLink),
                   mysql_real_escape_string($FTGTelecommunications, $mysqlLink),
	   mysql_real_escape_string($FTGingram, $mysqlLink),
                   mysql_real_escape_string($FTGcellnet, $mysqlLink),
                   mysql_real_escape_string($FTGaltech, $mysqlLink),
                   mysql_real_escape_string($FTGachieva, $mysqlLink),
                   mysql_real_escape_string($FTGalloys, $mysqlLink),
                   mysql_real_escape_string($FTGbrightpoint, $mysqlLink),
                   mysql_real_escape_string($FTGdicker, $mysqlLink),
                   mysql_real_escape_string($FTGexpress, $mysqlLink),
                   mysql_real_escape_string($FTGsimms, $mysqlLink),
                   mysql_real_escape_string($FTGtoday, $mysqlLink),
                   mysql_real_escape_string($FTGwestan, $mysqlLink),
                   mysql_real_escape_string($FTGdists, $mysqlLink),
                   mysql_real_escape_string($FTGOther, $mysqlLink));

@mysql_query($sqlCmd, $mysqlLink);

}
$mysqlLink = @mysql_connect("localhost", "login", "password");


if (mysql_errno() == 0) {

@mysql_select_db("database", $mysqlLink);


}


if (mysql_errno() == 0) {
$sqlCmd2 = sprintf("INSERT INTO callout(custcode, `Date`, Callout) VALUES ('%s', '%s', '%s')",
			   mysql_real_escape_string($FTGCustCode, $mysqlLink),
			   mysql_real_escape_string($FTGDate, $mysqlLink),
                   mysql_real_escape_string($FTGCallout, $mysqlLink));

@mysql_query($sqlCmd2, $mysqlLink);
}

# Embed success page and dump it to the browser

$fileSuccessPage = 'completed.php';

if (file_exists($fileSuccessPage) === false) {
echo '<html><head><title>Error</title></head><body>The success page: <b> ' . $fileSuccessPage . '</b> cannot be found on the server.</body></html>';
exit;
}

$successPage = ProcessPHPFile($fileSuccessPage);

$successPage = str_replace('<!--FIELDVALUE:CustCode-->', $FTGCustCode, $successPage);
$successPage = str_replace('<!--FIELDVALUE:CustName-->', $FTGCustName, $successPage);
$successPage = str_replace('<!--FIELDVALUE:StreetAddress-->', $FTGStreetAddress, $successPage);
$successPage = str_replace('<!--FIELDVALUE:Suburb-->', $FTGSuburb, $successPage);
$successPage = str_replace('<!--FIELDVALUE:State-->', $FTGState, $successPage);
$successPage = str_replace('<!--FIELDVALUE:TradingPattern-->', $FTGTradingPattern, $successPage);
$successPage = str_replace('<!--FIELDVALUE:MTD-->', $FTGMTD, $successPage);
$successPage = str_replace('<!--FIELDVALUE:PaymentType-->', $FTGPaymentType, $successPage);
$successPage = str_replace('<!--FIELDVALUE:LastMonth-->', $FTGLastMonth, $successPage);
$successPage = str_replace('<!--FIELDVALUE:BusinessType-->', $FTGBusinessType, $successPage);
$successPage = str_replace('<!--FIELDVALUE:Last3Months-->', $FTGLast3Months, $successPage);
$successPage = str_replace('<!--FIELDVALUE:PreferredShippingMethod-->', $FTGPreferredShippingMethod, $successPage);
$successPage = str_replace('<!--FIELDVALUE:YTD-->', $FTGYTD, $successPage);
$successPage = str_replace('<!--FIELDVALUE:Postcode-->', $FTGPostcode, $successPage);
$successPage = str_replace('<!--FIELDVALUE:Email-->', $FTGEmail, $successPage);
$successPage = str_replace('<!--FIELDVALUE:Telephone-->', $FTGTelephone, $successPage);
$successPage = str_replace('<!--FIELDVALUE:FAX-->', $FTGFAX, $successPage);
$successPage = str_replace('<!--FIELDVALUE:tdr-->', $FTGtdr, $successPage);
$successPage = str_replace('<!--FIELDVALUE:Notes-->', $FTGNotes, $successPage);
$successPage = str_replace('<!--FIELDVALUE:ProductFocus-->', $FTGProductFocus, $successPage);
$successPage = str_replace('<!--FIELDVALUE:NewCustomer-->', $FTGNewCustomer, $successPage);
$successPage = str_replace('<!--FIELDVALUE:Oem-->', $FTGOem, $successPage);
$successPage = str_replace('<!--FIELDVALUE:System-->', $FTGSystem, $successPage);
$successPage = str_replace('<!--FIELDVALUE:Peripherals-->', $FTGPeripherals, $successPage);
$successPage = str_replace('<!--FIELDVALUE:Consumables-->', $FTGConsumables, $successPage);
$successPage = str_replace('<!--FIELDVALUE:Telecommunications-->', $FTGTelecommunications, $successPage);
$successPage = str_replace('<!--FIELDVALUE:Other-->', $FTGOther, $successPage);
$successPage = str_replace('<!--FIELDVALUE:Input-->', $FTGInput, $successPage);
$successPage = str_replace('<!--FIELDVALUE:Date-->', $FTGDate, $successPage);
$successPage = str_replace('<!--FIELDVALUE:Callout-->', $FTGCallout, $successPage);
$successPage = str_replace('<!--FIELDVALUE:ingram-->', $FTGingram, $successPage);
$successPage = str_replace('<!--FIELDVALUE:cellnet-->', $FTGcellnet, $successPage);
$successPage = str_replace('<!--FIELDVALUE:achieva-->', $FTGachieva, $successPage);
$successPage = str_replace('<!--FIELDVALUE:simms-->', $FTGsimms, $successPage);
$successPage = str_replace('<!--FIELDVALUE:today-->', $FTGtoday, $successPage);
$successPage = str_replace('<!--FIELDVALUE:alloys-->', $FTGalloys, $successPage);
$successPage = str_replace('<!--FIELDVALUE:altech-->', $FTGaltech, $successPage);
$successPage = str_replace('<!--FIELDVALUE:brightpoint-->', $FTGbrightpoint, $successPage);
$successPage = str_replace('<!--FIELDVALUE:dicker-->', $FTGdicker, $successPage);
$successPage = str_replace('<!--FIELDVALUE:express-->', $FTGexpress, $successPage);
$successPage = str_replace('<!--FIELDVALUE:today-->', $FTGtoday, $successPage);
$successPage = str_replace('<!--FIELDVALUE:westan-->', $FTGwestan, $successPage);
$successPage = str_replace('<!--FIELDVALUE:dists-->', $FTGdists, $successPage);
$successPage = str_replace('<!--FIELDVALUE:MM_insert-->', $FTGMM_insert, $successPage);

echo $successPage;
exit;
?>
<?php echo $_SESSION['sessCustCode']; ?>
<?php echo $_SESSION['sessCustName']; ?>
<?php echo $_SESSION['sessStreetAddress']; ?>
<?php echo $_SESSION['sessPostcode']; ?>
<?php echo $_SESSION['sessEmail']; ?>
<?php echo $_SESSION['sessTelephone']; ?>
<?php echo $_SESSION['sessFAX']; ?>
<?php echo $_SESSION['sesstdr']; ?>
<?php echo $_SESSION['sessNotes']; ?>
<?php echo $_SESSION['sessMTD']; ?>
<?php echo $_SESSION['sessLastMonth']; ?>
<?php echo $_SESSION['sessLast3Months']; ?>
<?php echo $_SESSION['sessYTD']; ?>
<?php echo $_SESSION['sessDate']; ?>
<?php echo $_SESSION['sessCallout']; ?>

Link to comment
Share on other sites

Hi All,

 

I've actually had a play arund with my MYSQL part of the script and have implemented the following which seems to have solved my own question:

 

I added some coding to the script to create another error page called "$custcoderror" which displays the duplication error. I also added the MYSQL "or die" function and pointed it to display $custcoderror.

 

Please see the below coding for the MYSQL part of my script.

#====================================================
# Dump field values to a MySQL table                =
#====================================================

$mysqlLink = @mysql_connect("localhost", "login", "password");

$custcoderror = '<html><head><title>Error</title></head><body><p align="center"> </p><p align="center"> </p><p align="center"> </p><p align="center"> </p><p align="center"> </p><p align="center"> </p><p align="center"> </p><p align="center"> </p><p align="center"> </p><p align="center" class="style1"> Customer was not added due to the customercode already existing in the database</p><p align="center"> </p><p align="center"><strong>Please hit the back button on your browser and amend the details</strong></p></body></html>';

if (mysql_errno() == 0) {

@mysql_select_db("nscteam_net_nsc", $mysqlLink);


}

if (mysql_errno() == 0) {

  $sqlCmd = sprintf("INSERT INTO customerdetails(custcode, custname, `Street Address`, Suburb, `State`, `Trading Pattern`, MTD, `Payment Type`, `Last Month`, `Business Type`, `Last 3 Months`, `Preferred Shipping Method`, `YTD`, `PostCode`, `Email`, `Telephone`, `FAX`, `TDR`, `Notes`, `Product Focus`, newcustomer, OEM, System, Peripherals, Consumables, Telecommunications, ingram, cellnet, altech, achieva, alloys, brightpoint, dicker, express, simms, today, westan, dists, Other) VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
                   mysql_real_escape_string($FTGCustCode, $mysqlLink),
                   mysql_real_escape_string($FTGCustName, $mysqlLink),
                   mysql_real_escape_string($FTGStreetAddress, $mysqlLink),
                   mysql_real_escape_string($FTGSuburb, $mysqlLink),
                   mysql_real_escape_string($FTGState, $mysqlLink),
                   mysql_real_escape_string($FTGTradingPattern, $mysqlLink),
                   mysql_real_escape_string($FTGMTD, $mysqlLink),
                   mysql_real_escape_string($FTGPaymentType, $mysqlLink),
                   mysql_real_escape_string($FTGLastMonth, $mysqlLink),
                   mysql_real_escape_string($FTGBusinessType, $mysqlLink),
                   mysql_real_escape_string($FTGLast3Months, $mysqlLink),
                   mysql_real_escape_string($FTGPreferredShippingMethod, $mysqlLink),
                   mysql_real_escape_string($FTGYTD, $mysqlLink),
                   mysql_real_escape_string($FTGPostcode, $mysqlLink),
                   mysql_real_escape_string($FTGEmail, $mysqlLink),
                   mysql_real_escape_string($FTGTelephone, $mysqlLink),
                   mysql_real_escape_string($FTGFAX, $mysqlLink),
                   mysql_real_escape_string($FTGtdr, $mysqlLink),
                   mysql_real_escape_string($FTGNotes, $mysqlLink),
                   mysql_real_escape_string($FTGProductFocus, $mysqlLink),
                   mysql_real_escape_string($FTGNewCustomer, $mysqlLink),
                   mysql_real_escape_string($FTGOem, $mysqlLink),
                   mysql_real_escape_string($FTGSystem, $mysqlLink),
                   mysql_real_escape_string($FTGPeripherals, $mysqlLink),
                   mysql_real_escape_string($FTGConsumables, $mysqlLink),
                   mysql_real_escape_string($FTGTelecommunications, $mysqlLink),
	   mysql_real_escape_string($FTGingram, $mysqlLink),
                   mysql_real_escape_string($FTGcellnet, $mysqlLink),
                   mysql_real_escape_string($FTGaltech, $mysqlLink),
                   mysql_real_escape_string($FTGachieva, $mysqlLink),
                   mysql_real_escape_string($FTGalloys, $mysqlLink),
                   mysql_real_escape_string($FTGbrightpoint, $mysqlLink),
                   mysql_real_escape_string($FTGdicker, $mysqlLink),
                   mysql_real_escape_string($FTGexpress, $mysqlLink),
                   mysql_real_escape_string($FTGsimms, $mysqlLink),
                   mysql_real_escape_string($FTGtoday, $mysqlLink),
                   mysql_real_escape_string($FTGwestan, $mysqlLink),
                   mysql_real_escape_string($FTGdists, $mysqlLink),
                   mysql_real_escape_string($FTGOther, $mysqlLink));

@mysql_query($sqlCmd, $mysqlLink)or die($custcoderror);

}
$mysqlLink = @mysql_connect("localhost", "login", "password");


if (mysql_errno() == 0) {

@mysql_select_db("nscteam_net_nsc", $mysqlLink);


}


if (mysql_errno() == 0) {
$sqlCmd2 = sprintf("INSERT INTO callout(custcode, `Date`, Callout) VALUES ('%s', '%s', '%s')",
			   mysql_real_escape_string($FTGCustCode, $mysqlLink),
			   mysql_real_escape_string($FTGDate, $mysqlLink),
                                   mysql_real_escape_string($FTGCallout, $mysqlLink));

@mysql_query($sqlCmd2, $mysqlLink);
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.