homer_3 Posted February 27, 2014 Share Posted February 27, 2014 I'm using sql with php and mysql_fetch_assoc is returning null even though mysql_num_rows returns 1. I've echoed the query statement I'm using and entered the output manually and sql does return a value. I'm not sure why the code is returning a null. Basically I have $rv = mysql_query("SELECT (blah) from my_table WHERE my_key = " . $value . ";", $mysql_link); echo "" . mysql_num_rows($rv); if(!$rv) { echo 'There was a problem with your order. '; die('Could not connect: ' . mysql_error($mysql_link)); }else { if ($row = mysql_fetch_assoc($sql)) { //code }else { echo 'There was a problem setting up your order. '; die('Missing fields: ' . mysql_error($mysql_link)); } } And the missing fields is printing out even though echo "" . mysql_num_rows($rv); shows 1. Link to comment https://forums.phpfreaks.com/topic/286566-mysql_num_rows-returns-1-but-mysql_fetch_assoc-returns-null/ Share on other sites More sharing options...
kicken Posted February 27, 2014 Share Posted February 27, 2014 if ($row = mysql_fetch_assoc($sql)) You're using the wrong variable. $sql should be $rv. Link to comment https://forums.phpfreaks.com/topic/286566-mysql_num_rows-returns-1-but-mysql_fetch_assoc-returns-null/#findComment-1470861 Share on other sites More sharing options...
homer_3 Posted February 27, 2014 Author Share Posted February 27, 2014 Thanks, that's what I get for copy pasting code around. Didn't notice that. Link to comment https://forums.phpfreaks.com/topic/286566-mysql_num_rows-returns-1-but-mysql_fetch_assoc-returns-null/#findComment-1470862 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.