nca Posted October 4, 2022 Share Posted October 4, 2022 I am trying to rewrite a script from php 5 to php 7. Can someone help me see why this is not working? Thank you!! $db_connection = mysqli_connect($host, $user, $password, $database); $sql = "SELECT BIN FROM listofbins WHERE PENDING='1' LIMIT 1"; $result = mysqli_query($db_connection,$sql); $owew = mysqli_fetch_array($result, MYSQLI_ASSOC); if ($owew[BIN] > '100') { echo "Pending BIN over the number 100: $owew[BIN]"; exit; } Quote Link to comment https://forums.phpfreaks.com/topic/315395-help-with-mysqli_fetch_array/ Share on other sites More sharing options...
requinix Posted October 4, 2022 Share Posted October 4, 2022 We aren't sitting at your computer watching you work. We have no idea what it's doing or what you expect it to be doing. Saying it "doesn't work" is helpful to you but doesn't mean anything to us. What is "not working"? Quote Link to comment https://forums.phpfreaks.com/topic/315395-help-with-mysqli_fetch_array/#findComment-1601310 Share on other sites More sharing options...
Solution benanamen Posted October 4, 2022 Solution Share Posted October 4, 2022 Is BIN actually a Constant? I suspect it is not. $owew[BIN] Quote Link to comment https://forums.phpfreaks.com/topic/315395-help-with-mysqli_fetch_array/#findComment-1601311 Share on other sites More sharing options...
ginerjm Posted October 4, 2022 Share Posted October 4, 2022 If you need to find the record with the value of PENDING equaling 1, why do you need a limit? And is PENDING an integer or a text value? You make it appear to be a text one. In your query you have a field called BIN. Yet in your reference to the values retrieved from the query result you seem to be looking for a constant named BIN. Which is it? And again - is BIN an integer or is it a string? So many questions. Here is a sample of how I would write your query to do some error checking. You need to address my questions tho. if (!$db_connection = mysqli_connect($host, $user, $password, $database)) { echo "Could not make db connection"; exit(); } $sql = "SELECT BIN FROM listofbins WHERE PENDING='1' LIMIT 1"; if (!$result = mysqli_query($db_connection,$sql)) { echo "Error running query: $sql<br>"; exit(); } $owew = mysqli_fetch_array($result, MYSQLI_ASSOC); if ($owew['BIN]' > '100') { echo "Pending BIN over the number 100: ". $owew['BIN']; } exit(); Quote Link to comment https://forums.phpfreaks.com/topic/315395-help-with-mysqli_fetch_array/#findComment-1601329 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.