Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2009
    Location
    Tampa, FL
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    calculations after post

    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]

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    PHP Code:
    NOT!
    $total_cost = ($pallets *= $price);
    Instead
    $total_cost 
    $pallets*$price;
    // And make sure it know the values are numbers and not strings. 

  • #3
    New Coder
    Join Date
    Jul 2009
    Location
    Tampa, FL
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts
    still coming up with a value of 0. I posted the whole page to look at.

    Code:
    <?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>

  • #4
    New to the CF scene
    Join Date
    Jul 2012
    Location
    New Delhi, India
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    I think you need to replace

    PHP Code:
    $pallets $POST['pal_del'];
    $price $POST['pal_price']; 
    By

    PHP Code:
    $pallets $_POST['pal_del'];
    $price $_POST['pal_price']; 
    and anyways you can always debug by doing echo for all the variables.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •