Quote:
Originally Posted by CouponGuy
Are you trying to subtract values coming from the SQL data, or from values entered on the webpage's form?
If the data comes from SQL:
PHP Code:
<?php //make sure the field names, table name and conditions are accurate $sql = "select input_qty, output_qty from example_tablename where example_field = 1"; $sqlresult = mysql_query($sql) or die("Error executing SQL query"); $row = mysql_fetch_array($sqlresult); $inqty = $row['input_qty']; $outqty = $row['output_qty']; $qty = $inqty - $outqty; ?> <html> <body> Input_Qty: <?php echo $inqty; ?> Output_Qty: <?php echo $outqty; ?> Qty (In - Out): <?php echo $qty; ?> </body> </html>
If the data comes from the form:
PHP Code:
<?php $inqty = $_POST['input_qty']; $outqty = $_POST['output_qty']; $qty = $inqty - $outqty; ?> <html> <body> <form method="post" action="thispage.php"> <!-- thispage.php is whatever this page's filename is --> Input_Qty: <input type="text" name="input_qty" value="<?php echo $inqty; ?>" /> Output_Qty: <input type="text" name="output_qty" value="<?php echo $outqty; ?>" /> Qty (In - Out): <input type="text" name="qty" value="<?php echo $qty; ?>" /> </form> </body> </html> ?>
|
I try the 2nd code you suggested:
PHP Code:
<?php $inqty = $_POST["inqty"]; $outqty = $_POST["outqty"]; $varqty = $_POST["varqty"]; $varqty = $inqty - $outqty; echo "\n\t\t<td><input size='6' type='text' name='inqty[]' value='<?php echo $inqty; ?>' id='inqty" . $ctr . "' onkeypress='return handleEnter(event,\"outqty" . $ctr . "\");' /></td>"; echo "\n\t\t<td><input size='6' type='text' name='outqty[]' value='<?php echo $outqty; ?>' id='outqty" . $ctr . "' onkeypress='return handleEnter(event,\"idno" . $ctr . "\");' /></td>"; echo "\n\t\t<td><input size='6' type='text' name='varqty[]' value='<?php echo $varqty; ?>' id='varqty" . $ctr . "' onkeypress='return handleEnter(event,\"varsublot" . $ctr . "\");' /></td>";\ ?>
And I got this error:
and at the last row textfield, the php echo was appear
Fatal error: Unsupported operand types in D:\xampp\htdocs\INTRANET\clt_main.php on line 26
Last edited by newphpcoder; 12-12-2010 at 07:18 PM..
|