...

View Full Version : calculations after post



Mtruffa
08-17-2012, 04:32 PM
I have a form and I need to calculate a entry based on the post of the form. I need to calculate total cost from the price and number from the form. here is what I have so far and all i get is 0.

[CODE]
<?php
$err = array();

if($_POST['doDeliver'] == 'Enter Del')
{
if(empty($err)) {
$pallets = $POST['pal_del'];
$price = $POST['pal_price'];
$total_cost = ($pallets *= $price);


$sql_insert = "INSERT into `deliveries`
(`id`,`del_date`,`trail_num`,`pal_del`,`pal_grd`,`pal_price`,`debit`)
VALUES
('$_POST[id]','$_POST[del_date]','$_POST[trail_num]','$_POST[pal_del]','$_POST[pal_grd]','$_POST[pal_price]','$total_cost') ";

mysql_query($sql_insert,$link) or die("Insertion Failed:" . mysql_error());
}

}


?>
[CODE]

DrDOS
08-17-2012, 05:21 PM
NOT!
$total_cost = ($pallets *= $price);
Instead
$total_cost = $pallets*$price;
// And make sure it know the values are numbers and not strings.

Mtruffa
08-17-2012, 06:05 PM
still coming up with a value of 0. I posted the whole page to look at.




<?php
include 'dbc.php';
page_protect();

if(!checkAdmin()) {
header("Location: login.php");
exit();
}

$page_limit = 10;




// filter GET values
foreach($_GET as $key => $value) {
$get[$key] = filter($value);
}

foreach($_POST as $key => $value) {
$post[$key] = filter($value);
}


$rs_all = mysql_query("select count(*) as total_all from users") or die(mysql_error());


list($all) = mysql_fetch_row($rs_all);
?>
<?php
$sql="SELECT id, user_name, company FROM users WHERE user_name <> 'admin'";
$result=mysql_query($sql) or die(mysql_error());

$options="";

while ($row=mysql_fetch_array($result)) {

$id=$row["id"];
$thing=$row["company"];
$options.="<OPTION VALUE=\"$id\">".$thing.'</option>';
}
?>



<?php
$err = array();

if($_POST['doDeliver'] == 'Enter Del')
{
if(empty($err)) {
$pallets = $POST['pal_del'];
$price = $POST['pal_price'];
$total_cost = $pallets*$price;

$sql_insert = "INSERT into `deliveries`
(`id`,`del_date`,`trail_num`,`pal_del`,`pal_grd`,`pal_price`,`debit`)
VALUES
('$_POST[id]','$_POST[del_date]','$_POST[trail_num]','$_POST[pal_del]','$_POST[pal_grd]','$pal_price','$total_cost') ";

mysql_query($sql_insert,$link) or die("Insertion Failed:" . mysql_error());
}

}


?>
<html>
<head>
<title>USMI Pallets, Inc. :: Delivery Entry Main Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="styles.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script language="JavaScript" type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
<script language="JavaScript" type="text/javascript" src="js/jquery-ui-1.8.22.custom.min.js">
</script>
<link href="jquery-ui-1.8.22.custom.css" rel="stylesheet" type="text/css">
<script>
$(function() {
$( "#datepicker" ).datepicker({ dateFormat: "yy-dd-mm" });
});
</script>
</head>

<body>


<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="14%" valign="top"><?php
if (isset($_SESSION['user_id'])) {?>
<div class="myaccount">
<p><strong>Admin Center</strong></p>
<a href="admin.php">Admin Home</a><br>
<a href="pickup_ent.php">Pickups Entry</a><br>
<a href="delivery_ent.php">Delivery Entry</a><br>
<a href="payment_ent.php">Payment Entry</a><br>

<a href="logout.php">Logout </a>


<?php } ?>
</td>
<td width="74%" valign="top" style="padding: 10px;"><h2><font color="#FF0000">Delivery Entry
Page</font></h2>

<p>&nbsp;</p>
<form name "deliveryform" action="delivery_ent.php" method="post">
<table width="80%" border="0" align="center" cellpadding="10" cellspacing="0" style="background-color: #E4F8FA;padding: 2px 5px;border: 1px solid #CAE4FF;" >
<tr>
<td>
Account:
<SELECT NAME=id>
<OPTION VALUE=0>Choose
<?=$options?>
</SELECT> </td>
</tr>
<tr>
<td>Date: <input name="del_date" type="text" id="datepicker" /></td>
</tr>
<tr>
<td>Trailer #:<select name="trail_num" id="trail_num">
<option selected value=""></option>
<option value="1986-1">1986-1</option>
<option value="1986-2">1986-2</option>
<option value="1986-3">1986-3</option>
<option value="1986-4">1986-4</option>
<option value="1986-5">1986-5</option>
<option value="1986-6">1986-6</option>
<option value="1986-7">1986-7</option>
<option value="1986-8">1986-8</option>
<option value="1986-9">1986-9</option>
<option value="1986-10">1986-10</option>
<option value="1986-11">1986-10</option>
<option value="1986-12">1986-12</option>
</select></td>
</tr>
<tr>
<td>Pallets Delivered: <input id="pal_del" name="pal_del" size="8"></td>
</tr>
<tr>
<td>Grade:<select name="pal_grd" id="pal_grd">
<option selected value=""></option>
<option value="A">Garde A</option>
<option value="B">Grade B</option>
<option value="C">Grade C</option>
</select></td>
</tr>
<tr>
<td>Pallet Price: <input id="pal_price" name="pal_price" size="8" ></td>
</tr>
<tr>
<td><input name="doDeliver" type="submit" id="doDeliver" value="Enter Del"></p>
</td>
</tr>

</table>
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p></td>
<td width="12%">&nbsp;</td>
</tr>
</table>

</body>
</html>

qtriangle
08-17-2012, 06:32 PM
I think you need to replace



$pallets = $POST['pal_del'];
$price = $POST['pal_price'];
By



$pallets = $_POST['pal_del'];
$price = $_POST['pal_price'];

and anyways you can always debug by doing echo for all the variables.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum