jeff5656 Posted August 9, 2009 Share Posted August 9, 2009 When I run this line of code, the die part kicks in: $query2 = "SELECT * FROM `bundle` WHERE `pt_id` = '".$_POST['id_incr']."' and `bundle_date` = '$current_date'"; $result2 = mysql_fetch_array(mysql_query($query2)) or die("Invalid query: " . mysql_error()); I get this: Invalid query: And that's it. So it "dies" but there is no error?? Is this because the condition is false (i.e. there is no record with that match)? Link to comment https://forums.phpfreaks.com/topic/169472-theres-an-error-but-it-wont-tell-me-what-it-is/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 9, 2009 Share Posted August 9, 2009 The query is succeeding but matches/returns no rows. mysql_fetch_array() returns a false because there is no row and the or die() is using that false value, not the value that is returned by mysql_query(). The or die(), when used, would need to be used with the mysql_query() statement, not a mysql_fetch_array() statement. You should not nest function calls mysql_fetch_array(mysql_query($query2)) because that prevents using error checking, error reporting, and error recovery on the actual statement that can fail, the mysql_query(). Link to comment https://forums.phpfreaks.com/topic/169472-theres-an-error-but-it-wont-tell-me-what-it-is/#findComment-894143 Share on other sites More sharing options...
jeff5656 Posted August 9, 2009 Author Share Posted August 9, 2009 Wait now I changed it so there is no error but the $vent_id is blank! $query2 = "SELECT * FROM `bundle` WHERE `pt_id` = '".$_POST['id_incr']."' and `bundle_date` = '$current_date'"; $result2 = mysql_query($query2) or die("Invalid query: " . mysql_error()); $vent_id = $result2['vent_id']; echo "ventid is".$vent_id; the vent_id is blank which means $result2['vent_id'] is blank but it is not because that's a primary key! Is there somethign wrong with the query? Link to comment https://forums.phpfreaks.com/topic/169472-theres-an-error-but-it-wont-tell-me-what-it-is/#findComment-894144 Share on other sites More sharing options...
smerny Posted August 9, 2009 Share Posted August 9, 2009 $search2 = "SELECT * FROM `bundle` WHERE `pt_id` = '".$_POST['id_incr']."' and `bundle_date` = '$current_date'"; $result2 = mysql_query($search2) or die("Invalid query: " . mysql_error()); $row2= mysql_fetch_array($result2); $vent_id = $row2['vent_id']; echo "ventid is".$vent_id; edit: oops, fixed error Link to comment https://forums.phpfreaks.com/topic/169472-theres-an-error-but-it-wont-tell-me-what-it-is/#findComment-894145 Share on other sites More sharing options...
jeff5656 Posted August 9, 2009 Author Share Posted August 9, 2009 sorry didnt see your midify Link to comment https://forums.phpfreaks.com/topic/169472-theres-an-error-but-it-wont-tell-me-what-it-is/#findComment-894146 Share on other sites More sharing options...
PFMaBiSmAd Posted August 9, 2009 Share Posted August 9, 2009 You are no longer fetching a row from the result set. $result2 is a result resource and $result2['vent_id'] does not exist, so $vent_id is a NULL value. I recommend using mysql_fetch_assoc instead of mysql_fetch_array. You should be developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON in your php.ini to get php to help you. Stop and start your web server to get any change made to php.ini to take effect and use a phpinfo(); statement to confirm that those settings have actually been changed. Since there is no error from the mysql_error() statement, it means your WHERE clause did not match any rows in your table. echo $query2 to see exactly what it contains. @smerny when you start altering variable names for no specific purpose (Edit:see jeff5656's post above before he edited it) from what the OP already understands, it does not help. Also posting "fixed" code without an explanation of what was wrong or what change was made in it does not help anyone learn. Link to comment https://forums.phpfreaks.com/topic/169472-theres-an-error-but-it-wont-tell-me-what-it-is/#findComment-894151 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.