MrTV
asked on
php code stop when no result, Plese pro tect it to run the following code
if (Recordset_Inserting($fiel dList)) {
$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_idComSetDetai l))) {
$bCheckKey = false;
} else {
$sFilter = str_replace("@idComSetDeta il", AdjustSql($x_idComSetDetai l), $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_ComSetH eadId"]) : "NULL";
$fieldList["`ComSetHeadId` "] = $theValue;
// Field AOLcode
$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_AOL code"]) : $GLOBALS["x_AOLcode"];
$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
$fieldList["`AOLcode`"] = $theValue;
// Field ProductCussification
$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_Pro ductCussif ication"]) : $GLOBALS["x_ProductCussifi cation"];
$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
$fieldList["`ProductCussif ication`"] = $theValue;
// Field RemovefromSet
$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_Rem ovefromSet "]) : $GLOBALS["x_RemovefromSet" ];
$theValue = (strtoupper($theValue) != "Y") ? " 'N'" : " 'Y'";
$fieldList["`RemovefromSet `"] = $theValue;
// Inserting event
if (Recordset_Inserting($fiel dList)) {
$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["`idComSetDetai l`"] = phpmkr_insert_id($conn);
$result = (phpmkr_affected_rows($con n) > 0);
// Inserted event
if ($result) Recordset_Inserted($fieldL ist);
} else {
$result = false;
}
return $result;
}
$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_idComSetDetai
$bCheckKey = false;
} else {
$sFilter = str_replace("@idComSetDeta
}
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
phpmkr_free_result($rsChk)
return false;
}
phpmkr_free_result($rsChk)
}
// Field ComSetHeadId
$theValue = ($GLOBALS["x_ComSetHeadId"
$fieldList["`ComSetHeadId`
// Field AOLcode
$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_AOL
$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
$fieldList["`AOLcode`"] = $theValue;
// Field ProductCussification
$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_Pro
$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
$fieldList["`ProductCussif
// Field RemovefromSet
$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_Rem
$theValue = (strtoupper($theValue) != "Y") ? " 'N'" : " 'Y'";
$fieldList["`RemovefromSet
// Inserting event
if (Recordset_Inserting($fiel
$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["`idComSetDetai
$result = (phpmkr_affected_rows($con
// Inserted event
if ($result) Recordset_Inserted($fieldL
} else {
$result = false;
}
return $result;
}
ASKER
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\manager\Co mSetDetail add.php on line 361
serial number not exist
serial number not exist
ASKER
Hi yodercm
when i change it show above
if (Recordset_Inserting($fiel dList)) {
$sSql2 = "SELECT PCode FROM prddtl WHERE SerialNo1 = $x_AOLcode ";
$result01 = "mysql_query($sSql2, $conn)" ;
$numrows = mysql_num_rows($result01);
if ($numrows == 0)
{
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 .= ")";
when i change it show above
if (Recordset_Inserting($fiel
$sSql2 = "SELECT PCode FROM prddtl WHERE SerialNo1 = $x_AOLcode ";
$result01 = "mysql_query($sSql2, $conn)" ;
$numrows = mysql_num_rows($result01);
if ($numrows == 0)
{
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 .= ")";
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$sSql2 = "SELECT PCode FROM prddtl WHERE SerialNo1 = $x_AOLcode ";
$result01 = "mysql_query($sSql2, $conn)" ;
if(!$result01)
{
echo "serial number not exist" ;
die();
}
The statement
if(!$result01)
only checks if the query itself failed, not if there were no rows selected.
Instead, you can use
$numrows = mysql_num_rows($result01);
if ($numrows == 0)
{
echo "serial number not exist" ;
die();
}