Jump to content

Simple MySql query using PHP 5.3.1


Fabian_Giudici

Recommended Posts

Hi,

I'm asking for your help because I noticed that one of my PHP codes stopped working after I upgraded to PHP 5.3.1.

 

This is my code:

<?php

if (isset($_POST['submitted'])) {
include('connect.php');

$upc = 'item_no';
$criteria = $_POST['criteria'];
$query = "SELECT item_no, qty_on_hand, qty_on_ord, qty_allocated, (qty_on_hand - qty_allocated) as Total1, (qty_on_hand + qty_on_ord - qty_allocated) as Total2 FROM IMINVLOC_SQL WHERE $upc LIKE '%".$criteria."%'";
$result = mysqli_query($dbcon, $query) or die('error getting data');
$num_rows = mysqli_num_rows($result);

echo "$num_rows results found";
echo "<table>";
echo "<tr> <th>Item Number</th> <th style='text-align:right'>Available Now</th> <th style='text-align:right'>Available After Arrivals</th> </tr>";

while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {

    echo "<tr><td>";
	echo $row ['item_no'];
	echo "</td><td style='text-align:right'>";
	echo $row ['Total1'];
    echo "</td><td style='text-align:right'>";
	echo $row ['Total2'];
	echo "</td></tr>";
	
}

echo "</table>";
	
	
	
}

For some reason I keep getting the message (error getting data) which means there is something wrong on my line 8.

Can you guys help me please?

Thanks!

 

Btw, I checked the DB connection individually and it seems to connect just fine so the file connect.php isn't the issue I guess.

Link to comment
https://forums.phpfreaks.com/topic/277152-simple-mysql-query-using-php-531/
Share on other sites

Ok, this are the 2 files I have.

 

connect.php

<?php

$dbcon = new mysqli('127.0.0.1', 'database_user', 'database_pass', 'database_stock');

?>

index.php

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Inventory Query</title>
<style type="text/css">
<!--
@import url("style.css");
-->
</style>
</head>
<body id="gradient-style">
<h1>Inventory Query</h1>

<form action="index.php" method="post" id="enter">
<input type="hidden" name="submitted" value="true" />

<label>Enter Item Number:<input type="text" name="criteria" /></label>

<input type="submit" value="Search" />

</form><br>
<?php

if (isset($_POST['submitted'])) {
include('connect.php');

$upc = 'item_no';
$criteria = $_POST['criteria'];
$query = "SELECT item_no, qty_on_hand, qty_on_ord, qty_allocated, (qty_on_hand - qty_allocated) as Total1, (qty_on_hand + qty_on_ord - qty_allocated) as Total2 FROM IMINVLOC_SQL WHERE $upc LIKE '%".$criteria."%'";
$result = mysqli_query($dbcon, $query) or die('error getting data');
$num_rows = mysqli_num_rows($result);

echo "$num_rows results found";
echo "<table>";
echo "<tr> <th>Item Number</th> <th style='text-align:right'>Available Now</th> <th style='text-align:right'>Available After Arrivals</th> </tr>";

while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {

    echo "<tr><td>";
	echo $row ['item_no'];
	echo "</td><td style='text-align:right'>";
	echo $row ['Total1'];
    echo "</td><td style='text-align:right'>";
	echo $row ['Total2'];
	echo "</td></tr>";
	
}

echo "</table>";
	
	
	
} // end of main statment

?>
</body>
</html>

I have a database called _stock with 1 tables and 4 columns

 

Table:

IMINVLOC_SQL

 

Columns:

1 item_no

2 qty_on_hand

3 qty_on_ord

4 qty_allocated

 

It was working just fine before I upgraded my PHP from 5.1 to 5.3 I think.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.