/    Sign up×
Community /Pin to ProfileBookmark

error: Call to Undefined Function

Hi..

I have a function for convert to dozen.

here is my code:

[code=php]
<?php
error_reporting(0);
date_default_timezone_set(“Asia/Singapore”); //set the time zone
$con = mysql_connect(‘localhost’, ‘root’,”);

if (!$con) {
echo ‘failed’;
die();
}

mysql_select_db(“mes”, $con);
$Date_Shelve =date(‘Y-m-d H:i:s’);

?>
<html>
<head>
<title>Job Order</title>
<link rel=”stylesheet” type=”text/css” href=”kanban.css” />
</head>
<body>

<div id=”ddcolortabs”>
<ul>
<li id=”current”> <a href=”SalesOrder.php” title=”Sales Order”><span>Order Management</span></a></li>
<li> <a href=”ParameterSettings.php” title=”Parameter Settings”><span>Parameter Settings</span></a></li>
<li style=”margin-left: 1px”><a href=”kanban_report.php” title=”WIP Report”><span>WIP Report</span></a></li>
<li><a href=”fsn.php” title=”Finished Stock Note”><span>WMS FG</span></a></li>
<li><a href=”ReceivingMaterials.php” title=”WMS RM”><span>WMS RM</span></a></li>
</ul>
</div>
<div id=”ddcolortabs1″>
<ul>
<li><a href=”SalesOrder.php” title=”Sales Order”><span>Sales Order</span></a></li>
<li id=”current”><a href=”JobOrder.php” title=”Job Order”><span>Job Order</span></a></li>
</ul>
</div>

<div id=”SR_date”>

<input type=”hidden” name=”Date_Shelve” id=”Date_Shelve” value=”<?php echo $Date_Shelve; ?>” size=”16″ readonly=”readonly” style=”border: none;”>
</div>

<?php
//—-approve button—–//
$Approved = isset($_POST[‘priority’]);
if ($Approved)
{
$PO_No = $_POST[‘PO_No’];
$ETD = $_POST[‘ETD’];
$SKUCode = $_POST[‘SKUCode’];
$Description = $_POST[‘Description’];
$POReq = $_POST[‘POReq’];
$priority = $_POST[‘priority’];

$sql = “SELECT SKUCode, Materials, Comp, Qty
FROM bom WHERE SKUCode = ‘$SKUCode'”;
$res = mysql_query($sql, $con);

$row = mysql_fetch_assoc($res);
$Materials = $row[‘Materials’];
$Qty = $row[‘Qty’];
$Comp = $row[‘Comp’];

$ReqQty = $Qty * $POReq;

$sql = “UPDATE bom SET ReqQty = ‘$ReqQty’ WHERE SKUCode = ‘$SKUCode’ AND Materials = ‘$Materials'”;
$resReqQty = mysql_query($sql, $con);

$sql = “SELECT SUM(WEIGHING) AS WEIGHING_TOTAL, “;
$sql .= “SUM(COMPOUNDING) AS COMPOUNDING_TOTAL, “;
$sql .= “SUM(EXTRUSION) AS EXTRUSION_TOTAL, “;
$sql .= “SUM(FORMING) AS FORMING_TOTAL, “;
$sql .= “SUM(DIPPING) AS DIPPING_TOTAL, “;
$sql .= “SUM(MOULDING) AS MOULDING_TOTAL “;
$sql .= “FROM MES_REPORT_OPEN WHERE SUBSTRING(LOT_CODE, 9) = ‘$Comp'”;

$result = mysql_query($sql, $con);

$weighingTotal = mysql_result($result, 0, “WEIGHING_TOTAL”);
$weighingTotal = convertToDozen($weighingTotal, $Comp);
$weighingAccum = $weighingAccum + $weighingTotal;
$compoundingTotal = mysql_result($result, 0, “COMPOUNDING_TOTAL”);
$compoundingTotal = convertToDozen($compoundingTotal, $Comp);
$compoundingAccum = $compoundingAccum + $compoundingTotal;

$extrusionTotal = mysql_result($result, 0, “EXTRUSION_TOTAL”);
$extrusionTotal = convertToDozen($extrusionTotal, $Comp);
$extrusionAccum = $extrusionAccum + $extrusionTotal;

$formingTotal = mysql_result($result, 0, “FORMING_TOTAL”);
$formingTotal = convertToDozen($formingTotal, $Comp);
$formingAccum = $formingAccum = $formingTotal;

$dippingTotal = mysql_result($result, 0, “DIPPING_TOTAL”);
$dippingTotal = convertToDozen($dippingTotal, $Comp);
$dippingAccum = $dippingAccum + $dippingTotal;

$virtualY = $weighingTotal + $compoundingTotal + $extrusionTotal + $formingTotal;

$totalY = $dippingTotal + $virtualY;

function convertToDozen ($total, $cmpdType) {
switch ($cmpdType) {
case “P28” :
$convTotal = (($total * 1000) / 22.00) / 12;
break;
case “P30” :
$convTotal = (($total * 1000) / 25.10) / 12;
break;
case “P32” :
$convTotal = (($total * 1000) / 22.50) / 12;
break;
case “P33” :
$convTotal = (($total * 1000) / 25.00) / 12;
break;
case “P35” :
$convTotal = (($total * 1000) / 25.25) / 12;
break;
case “P35M” :
$convTotal = (($total * 1000) / 22.60) / 12;
break;
case “P35W” :
$convTotal = (($total * 1000) / 22.50) / 12;
break;
case “P38” :
$convTotal = (($total * 1000) / 26.70) / 12;
break;
case “P41” :
$convTotal = (($total * 1000) / 24.80) / 12;
break;
case “P42” :
$convTotal = (($total * 1000) / 18.90) / 12;
break;
case “P43” :
$convTotal = (($total * 1000) / 25.00) / 12;
break;
case “P46” :
$convTotal = (($total * 1000) / 27.00) / 12;
break;
case “P47” :
$convTotal = (($total * 1000) / 27.60) / 12;
break;
}
return round($convTotal, 2);
}
}
else{

}

$sql = “SELECT jo_number, ETD, PO_No, SKUCode, Description, POQty, Priority
FROM job_order ORDER BY jo_number, ETD”;
$res = mysql_query($sql,$con);
?>
<div id=”kanban_table” style=”overflow:auto; height:215px;”>
<table>
<th> JO No.</th>
<th> ETD </th>
<th> PO No. </th>
<th> SKU Code </th>
<th> Description </th>
<th> PO Req </th>
<th> Priority</th>
<?php
$sql = “SELECT ETD, PO_No, SKUCode, Description, POReq
FROM sales_order WHERE NOT EXISTS (SELECT PO_No FROM job_order WHERE job_order.PO_No = sales_order.PO_No) ORDER BY ETD, PO_No “;
$res_so = mysql_query($sql, $con);
while($row = mysql_fetch_assoc($res_so)){
echo “<form name=’joborder_form’ action=” method=’post’>”;
$PO_No = $row[‘PO_No’];
echo “<tr>
<td><input type=’text’ value=” style=’border:none;’ size=’10’></td>
<td><input type=’text’ name=’ETD’ id=’ETD’ value=’$row[ETD]’ style=’border:none;’ size=’10’></td>
<td><input type=’text’ name=’PO_No’ id=’PO_No’ value=’$row[PO_No]’ style=’border:none;’ size=’30’></td>
<td><input type=’text’ name=’SKUCode’ id=’SKUCode’ value=’$row[SKUCode]’ style=’border:none;’ size=’15’></td>
<td><input type=’text’ name=’Description’ id=’Description’ value=’$row[Description]’ style=’border:none;’ size=’35’></td>
<td><input type=’text’ name=’POReq’ id=’POReq’ value=’$row[POReq]’ style=’border:none;’ size=’10’></td>
<td><input type=’submit’ name=’priority’ value=’Approved’ id=’priority’></td>
</tr>”;
echo “</form>”;
}
echo “</table>”;
echo “</div>”;

echo “<div style=’overflow:auto; height:215px;’>”;
echo “<table>”;
while($row_job = mysql_fetch_assoc($res)){
echo “<tr>
<td><input type=’text’ name=’JO_No_’ id=’JO_No_’ value=’$row_job[jo_number]’ style=’border:none;width:auto;’ size=’10’></td>
<td><input type=’text’ name=’ETD_’ id=’ETD_’ value=’$row_job[ETD]’ style=’border:none;width:auto;’ size=’10’></td>
<td><input type=’text’ name=’PO_No_’ id=’PO_No_’ value=’$row_job[PO_No]’ style=’border:none;’ size=’30’></td>
<td><input type=’text’ name=’SKUCode_’ id=’SKUCode_’ value=’$row_job[SKUCode]’ style=’border:none;’ size=’15’></td>
<td><input type=’text’ name=’Description_’ id=’Description_’ value=’$row_job[Description]’ style=’border:none;’ size=’35’></td>
<td><input type=’text’ name=’POReq_’ id=’POReq_’ value=’$row_job[POQty]’ style=’border:none;width:auto;’ size=’10’></td>
<td><input type=’text’ name=’priority_’ value=’$row_job[Priority]’ id=’priority_’ style=’border:none;width:auto;’ size=’10’></td>
</tr>” ;
}
echo “</table>”;
echo “</div>”
?>

</body>
</html>
[/code]

but I when I echo this:

[code=php]
echo $weighingTotal;
[/code]

No result, then when I debug my code I got an error: Call to undefined function.

I can’t configured out where in my code was wrong?

Any help is highly appreciated.

Thank you

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 25.2012 — Move the function definition outside if the if() block. It will then get defined before any code actually gets processed, whereas if it is within a conditional block, then it does not get defined until that if() condition is triggered and the function definition code is actually executed. (As long as the function definition is not within any such conditional block, it will get defined first, regardless of its position in the script.)
Copy linkTweet thisAlerts:
@newphpcoderauthorApr 25.2012 — Thank you
×

Success!

Help @newphpcoder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...