Fabian_Giudici Posted April 19, 2013 Share Posted April 19, 2013 (edited) 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. Edited April 19, 2013 by Fabian_Giudici Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 19, 2013 Share Posted April 19, 2013 It would help to see the actual MySQL error message. mysqli_error() + the actual string. Quote Link to comment Share on other sites More sharing options...
Fabian_Giudici Posted April 19, 2013 Author Share Posted April 19, 2013 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. Quote Link to comment Share on other sites More sharing options...
seandisanti Posted April 19, 2013 Share Posted April 19, 2013 (edited) Did you read Jessica's message? Instead of just calling die() with a note that there is an error, make use of mysqli_error() to output the details of the error or die('error getting data<br />' . mysqli_error()); Edited April 19, 2013 by seandisanti Quote Link to comment Share on other sites More sharing options...
Fabian_Giudici Posted April 19, 2013 Author Share Posted April 19, 2013 Warning: mysqli_error() expects exactly 1 parameter, 0 given in/home/account1/public_html/stock/index.php on line 32error getting data Quote Link to comment Share on other sites More sharing options...
seandisanti Posted April 19, 2013 Share Posted April 19, 2013 That error means that it is expecting a parameter that was not provided. In this case i believe it's the reference to your db connection that you've used in every other mysqli_ call Quote Link to comment Share on other sites More sharing options...
Fabian_Giudici Posted April 19, 2013 Author Share Posted April 19, 2013 I provided with the connect php file I'm using so what do you think I should change to make it work? Funny thing is that it was working just fine before I upgraded PHP. Quote Link to comment Share on other sites More sharing options...
seandisanti Posted April 19, 2013 Share Posted April 19, 2013 or die('error getting data<br />' . mysqli_error($dbcon)); Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 19, 2013 Share Posted April 19, 2013 Funny thing is that it was working just fine before I upgraded PHP. Aside of the error that you got above, did you restart the http and the mysql server after upgrading php? BTW - nice Italian family Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.