Duplicate Writes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear List -

I seem to be getting dual writes causing a dual insert into the database, and I cannot figure out why.

Database

mysql> describe Inventory;
+-------------+-------------+------+-----+---------+-------+
| Field       | Type        | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| UPC         | char(12)    | NO   | PRI |         |       |
| quant       | int(5)      | NO   |     | NULL    |       |
| manuf       | varchar(20) | YES  |     | NULL    |       |
| item        | varchar(50) | YES  |     | NULL    |       |
| orderpt     | tinyint(4)  | NO   |     | NULL    |       |
| ordrpt_flag | tinyint(3)  | YES  |     | NULL    |       |
| stock       | int(3)      | YES  |     | NULL    |       |
| price       | float       | YES  |     | NULL    |       |
| tax_flag    | tinyint(3)  | YES  |     | NULL    |       |
+-------------+-------------+------+-----+---------+-------+
9 rows in set (0.37 sec)

mysql> describe Purchases;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| indx  | smallint(6) | NO   | PRI | NULL    | auto_increment |
| manf  | varchar(20) | YES  |     | NULL    |                |
| itm   | varchar(50) | YES  |     | NULL    |                |
| prc   | float       | YES  |     | NULL    |                |
+-------+-------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)


PHP code - snipped

error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors','1');

<html>
<?php


$fh1 = fopen("/var/www/orders.txt", "a+");
$fh2 = fopen("/var/www/receipt.txt", "a+");
$fh3 = fopen("/var/www/purchase.txt", "a+");
$sql2 = "update Inventory set quant = quant - 1 where UPC = $upc ";

$result2 = mysqli_query($cxn, $sql2);

$row2 = mysqli_fetch_row($result2);

$sql3 = "select quant, orderpt, ordrpt_flag, manuf, item, stock,price,tax_flag from Inventory where UPC = $upc";

$result3 = mysqli_query($cxn, $sql3);

?>
<div align="center">
<table border="4" cellpadding="5" cellspacing="55" rules="all" frame="box">
<tr class='heading'>
<th>Manufacturer</th>
<th>Item</th>
<th>Price</th>
</tr>						

<?php				
$row3 = mysqli_fetch_row($result3);

echo '<br />';
$Quant   =     $row3[0];
$Orderpt =     $row3[1];
$Ordrpt_flag = $row3[2];
$Manuf =       $row3[3];
$Item  =       $row3[4];
$Stock =       $row3[5];
$Price =       $row3[6];
$Tax   =       $row3[7];

$numbyt=fprintf($fh2, "%s\t %.2f\t\n %s\t %s\n",$row3[3] , $row3[6], $row3[4], $row3[7]);


$numbyt=fprintf($fh3, "%s,%s,%s, %.2f\n",NULL,$row3[3], $row3[4], $row3[6]);



if($row3[0] < $row3[1] )
echo "<center><b><span style='color: red; font-size:14pt';> Order more $row3[3] $row3[4] Now</b><br /> </span></center>";

$sql4 = "update Inventory set ordrpt_flag = 1 where UPC = $upc";

$result4 = mysqli_query($cxn, $sql4);

$numbyt=fprintf($fh1, "%d %d %d %s %s %d\n", $Quant, $Orderpt, $Ordrpt_flag, $Manuf, $Item, $Stock);
?>				

<tr>

<td> <?php echo $row3[3]; ?> </td>
<td> <?php echo $row3[4]; ?> </td>
<td> <?php echo $row3[6]; ?> </td>
</tr>
</table>		
<?php	

$sql5 = "load data infile '/var/www/purchase.txt' into table "
. "Purchases FIELDS TERMINATED BY ',' lines terminated by '\n' "; //There are dual writes to the //table

$result5 = mysqli_query($cxn, $sql5);
$sql26 = "SELECT SQL_CALC_FOUND_ROWS itm FROM Purchases ";

$result26 = mysqli_query($cxn, $sql26);
$sql27 = "SELECT FOUND_ROWS()";

$result27 =  mysqli_query($cxn, $sql27);
$row27 = mysqli_fetch_row($result27);

$sql25 = "select * from Purchases";
$result25 = mysqli_query($cxn, $sql25);
?>						

<div align="center">
<table border="4" cellpadding="5" cellspacing="55" rules="all" frame="box">
<tr class='heading'>
<th>Index</th>
<th>Manufacturer</th>
<th>Item</th>
<th>Price</th>
</tr>						

<?php				

	for($i = 0; $i <$row27[0]; $i++)
	{
		$row25 = mysqli_fetch_row($result25)
?>
		<tr>
		<td> <?php echo $row25[0]; ?> </td>
		<td> <?php echo $row25[1]; ?> </td>
		<td> <?php echo $row25[2]; ?> </td>
		<td> <?php echo $row25[3]; ?> </td>
		</tr>
<?php
		}
?>					
	</table>	


TIA

Ethan				
					



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux