troubleshooting Question

php code stop when no result, Plese pro tect it to run the following code

Avatar of teera
teera asked on
PHP
5 Comments2 Solutions260 ViewsLast Modified:
if (Recordset_Inserting($fieldList)) {
        $sSql2 = "SELECT PCode  FROM prddtl WHERE SerialNo1 = $x_AOLcode ";
        $result01 = "mysql_query($sSql2, $conn)" ;
                   if(!$result01)
        {
        echo "serial number not exist" ;
          die();
        }


How can i make the code stop not continue to run the following line if the SerialNo1  generate no Pcode

the code above when i put SerialNo1  that not axist it still run the following line

The full code is below



The full code is  below

function AddData($conn)
{
      global $x_idComSetDetail;
      global $x_ComSetHeadId;
      global $x_AOLcode;
      $sFilter = ewSqlKeyWhere;

      // Check for duplicate key
      $bCheckKey = true;
      if ((@$x_idComSetDetail == "") || (is_null(@$x_idComSetDetail))) {
            $bCheckKey = false;
      } else {
            $sFilter = str_replace("@idComSetDetail", AdjustSql($x_idComSetDetail), $sFilter); // Replace key value
      }
      if ($bCheckKey) {
            $sSqlChk = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, $sFilter, "");
            $rsChk = phpmkr_query($sSqlChk, $conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br>SQL: ' . $sSqlChk);
            if (phpmkr_num_rows($rsChk) > 0) {
                  $_SESSION[ewSessionMessage] = "Duplicate value for primary key";
                  phpmkr_free_result($rsChk);
                  return false;
            }
            phpmkr_free_result($rsChk);
      }

      // Field ComSetHeadId
      $theValue = ($GLOBALS["x_ComSetHeadId"] != "") ? intval($GLOBALS["x_ComSetHeadId"]) : "NULL";
      $fieldList["`ComSetHeadId`"] = $theValue;

      // Field AOLcode
      $theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_AOLcode"]) : $GLOBALS["x_AOLcode"];
      $theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
      $fieldList["`AOLcode`"] = $theValue;

      // Field ProductCussification
      $theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_ProductCussification"]) : $GLOBALS["x_ProductCussification"];
      $theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
      $fieldList["`ProductCussification`"] = $theValue;

      // Field RemovefromSet
      $theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_RemovefromSet"]) : $GLOBALS["x_RemovefromSet"];
      $theValue = (strtoupper($theValue) != "Y") ? " 'N'" : " 'Y'";
      $fieldList["`RemovefromSet`"] = $theValue;

      // Inserting event
      if (Recordset_Inserting($fieldList)) {


        $sSql2 = "SELECT PCode  FROM prddtl WHERE SerialNo1 = $x_AOLcode ";

        $result01 = "mysql_query($sSql2, $conn)" ;
       
            if(!$result01)
        {
        echo "serial number not exist" ;
          die();
        }
            
        $sSql1 = "UPDATE prdmas SET onhand = onhand - 1 WHERE Code = (SELECT PCode  FROM prddtl WHERE SerialNo1 = $x_AOLcode )  ";

            mysql_query($sSql1, $conn) or die("fail to deduct stock " . __LINE__ . ": " . phpmkr_error($conn) . '<br>SQL: ' . $sSql1);




            // Insert
            $sSql = "INSERT INTO `ComSetDetail` (";
            $sSql .= implode(",", array_keys($fieldList));
            $sSql .= ") VALUES (";
            $sSql .= implode(",", array_values($fieldList));
            $sSql .= ")";      
            phpmkr_query($sSql, $conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br>SQL: ' . $sSql);
            $fieldList["`idComSetDetail`"] = phpmkr_insert_id($conn);
            $result = (phpmkr_affected_rows($conn) > 0);

            // Inserted event
            if ($result) Recordset_Inserted($fieldList);
      } else {
            $result = false;
      }
      return $result;
}


ASKER CERTIFIED SOLUTION
Cornelia Yoder
Artist

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros