Re: [PHP-DB] Waiting for localhost

[email protected] (Ethan Rosenberg) Wed, 01 Apr 2015 00:05:29 -0400
Newsgroups php.db
Message-ID <[email protected]>
On 03/27/2015 06:16 AM, Richard wrote:
>
> <snip>
> ------------ Original Message ------------
> These errors look odd to me. In many years of working with apache on
> a range of *nix OSs, I don't remember a (properly installed) apache
> instance that didn't have defaults that worked out of the box. They
> may not have been what one wanted, but they worked.
>
> With errors like these I wouldn't expect the web server to start,
> but from previous exchanges I thought that it/one was running. Are
> you running more than one server? What do ps and netstat show.
>
> As these are web server, not php (and certainly not php-db), issues
> you should probably be asking them on the apache list.
>
> [i read the list, please do not include my direct email address in
> your messages.]
>
>
>     - Richard
>

Richard -

As we saw in the Apache list, the problem lies in PHP/MySQL

To quote --

"
Date: Tuesday, March 31, 2015 02:18:13 -0400
From: "Ethan Rosenberg, PhD" <[email protected]>
Subject: Re: [users@httpd] Apache is Slow

Some more info....

Changed the host in the connect

$cxn = mysqli_connect($host,$user,$password);

$host="127.0.1.1";

Now get an error...

Warning: mysqli_connect(): (HY000/2003): Can't connect to MySQL
server on '127.0.1.1' (111) in /var/www/HandleWeight.php on line 56
Connect Error (2003) Can't connect to MySQL server on '127.0.1.1'
(111)

The correct IPnumber for "localhost" is "127.0.0.1". I wouldn't
generally expect anything to answer on "127.0.1.1".

Separately, I think that this likely proves that this isn't an
apache issue. You're getting to the mysql reference in the php
script that  you're calling (from the js reference) and it's failing
there because of the incorrect IPnumber.

-->> So, apache is responding fine and it's seemingly your script that has problems.
"

All this having been said, I have attached HandleWeight.php Hopefully this will assist us in finding 
the error.

TIA

Ethan
HandleWeight2.php (application/x-httpd-php, 6.2 KB)
<?php
session_name("STORE");
session_set_cookie_params( '24000', '/' );
session_start();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
    <head>
        <title>Handle Weight</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<style>
			body{
				background-color: #89caeb; 
				width:100%;
				height:100%;
				position: relative;
   		        font-family: "Helvetica", "Arial" , "Liberation Sans", "Free sans", sans-serif;
				overflow-y: scroll;
 			}  			
		</style>		
	
    </head>
		<body>

			<strong>
			<div align='center'>
			  <!--<h3>Handle Weight</h3>-->
			</div>
			</strong>
<?php

			global $cxn, $open_flag, $sale, $tax_rate, $plu ; 

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

			
			require '/home/ethan/PHP/ethan.inc';
			
			$cxn = mysqli_connect($host,$user,$password);
			if (!$cxn) 
			{
				die('Connect Error (' . mysqli_connect_errno() . ') '
				. mysqli_connect_error());
			}
			if (mysqli_select_db($cxn, "Store") == 0)
			{
				die('Connect Error (' . mysqli_connect_errno() . ') '
				. mysqli_connect_error());				
			}
			$tax_rate = 0.08375;

			$fh1 = fopen("/var/www/orders.txt", "a+");
			$fh2 = fopen("/var/www/receipt.txt", "a+");
			$fh3 = fopen("/var/www/purchase.txt", "a+");
			if(!$fh3)
				var_dump($php_errormsg);
			$_POST['weighed'] = 1;
			
			$plu = $_SESSION['UPC'];
			$sql10 = "select Price, WeightFlag, InStock from Food where PLU=$plu";
			$result10 = mysqli_query($cxn, $sql10);
			$row10 = mysqli_fetch_row($result10);
			if(!isset($row10[2]))
			{
?>
				<br /><br /><center><b><span style="color: red; font-size:14pt;" >No Records Retrieved</b></span></center> 
<?php			
				Show_Welcome();
			}
			
			$weight=shell_exec("/var/www/scale7");
			echo "weight $weight";
			$cost = $weight*$row10[0];
			echo "<br />cost = "; 

			$sql1 = "select  Item, Type, Size, Price, PLU, WeightFlag, InStock, OrderPoint, "
				
				. "OPFlag, StockWanted from Food where PLU = $plu";

			$result1 = mysqli_query($cxn, $sql1) or 
				trigger_error("Query Failed! SQL: $sql1 - Error: ".mysqli_error($cxn), E_USER_ERROR);
			$row1 = mysqli_fetch_row($result1);

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


			<tr>
			<td> <?php echo $row1[0]; ?> </td>
			<td> <?php echo $row1[1]; ?> </td>
			<td> <?php echo $row1[2]; ?> </td>
			<td> <?php printf("%0.2f", $cost); ?> </td>
			<td> <?php echo $row1[4]; ?> </td>
			</tr>
			</table>		
<?php			

			

			$sql3 = "select InStock from Food where PLU = $plu ";
			$result3 = mysqli_query($cxn, $sql3);
			$row3 = mysqli_fetch_row($result3);
			
			$cost = $row1[3];
			$old_cost = $_SESSION['SALE'];
			$new_cost = $old_cost + $cost;
			$_SESSION['SALE'] = $new_cost;
			
			$sql4 = "update Food set InStock = (InStock - $weight) where PLU = $plu ";

			$numbyt=fprintf($fh2, "%s\t%s\t\n%s\t  %.2f\n\n",$row1[0] , $row1[1], $row1[2], $cost);
			fflush($fh2);
			$numbyt=fprintf($fh3, "%s,%s,%s, %.2f, %s\n",NULL,$row1[0], $row1[1], $cost, '0', $row1[4] );
			fflush($fh3);

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

			$sql9 = "update Inventory set ordrpt_flag = 1 where PLU = $plu";
			$result9 = mysqli_query($cxn, $sql9);
			
			Show_Welcome();
			
			function ShowPurchases()
			{
				global $cxn;
				$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

				}

			} //end ShowPurchases
			

		function Show_Welcome()
		{
			global $cxn, $fh1, $fh2, $fh3;
			echo "<br /><br />";
			echo "<form name='form1' action='a.php'  method='post'/ >";			
			echo "<center><input  type='text' name = 'UPC'  ></center><br /><br />";
			echo "<input type='hidden' name='welcome_already_seen' value='already_seen'>";
			echo "<input hidden='hidden' name='next_step' value='step3' ></input>";
			echo "<center><strong><input type = 'submit' value= 'Enter UPC'></strong></center>";
			echo "</form>";
			echo "<br/><br/><br/>";

			echo "<center>";
			echo "<form method='post' action='choice.php'>";
			echo "<strong><span style = 'font-size: 12pt';>RETURN to MENU?</strong><br /><br />";
			echo "<input type='submit' value = 'Return to Menu' ><br /><br /></input>";
			echo "</form>";
			echo "</span>";
			echo "</center>";


			echo "<center>";
			echo "<h2>Finished with Purchases?</h2>"; 
			echo "<form method='post' action=''>";
			echo "<input type='radio' name='prnt' value='yes'>Yes</input>";
			echo "<input type='radio' name='prnt' value='no'>  No</input><br /><br />";  
			echo "<input type='submit' value='Choose Yes/No and Click' /><br /><br />";
			echo "</form>";
			echo "</center>";


			echo "<center>";
			echo "<h2>Remove a Purchase?</h2>"; 
			echo "<form method='post' action=''>";
			echo "<input type='radio' name='rmv' value='yes'>Yes</input>";
			echo "<input type='radio' name='rmv' value='no'>  No</input><br /><br />";  
			echo "<input type='submit' value='Choose Yes/No and Click' /><br /><br />";
			echo "</form>";
			echo "</center>";
			
			if($_POST['prnt'] =='yes')
			{	

?>
				<script type="text/javascript">
				<!--
				window.open("PrintReceipt.php","_self")
				//-->\
				</script>
<?php						
			
						
			}	

		}	//end Show_Welcome
						
?>				

		</body>
</html>