darkfreaks Posted February 11, 2008 Share Posted February 11, 2008 can anyone get this one ??? <?php $query = "INSERT INTO `vc_covenmembers` (`username`,`date`,`covenname`,`approvalreason`,`approved`) VALUES('{$username}','{$date}','{$covenname}','{$approvalreason}','{$approved}')"; $result=mysql_query($query) or die(mysql_error()); $num=mysql_num_rows($result); if($num=>0){ echo"You are already a Member of $covenname"; } ?> Link to comment https://forums.phpfreaks.com/topic/90561-mysql_num_rows-not-a-valid-resource/ Share on other sites More sharing options...
revraz Posted February 11, 2008 Share Posted February 11, 2008 Your query is failing. Link to comment https://forums.phpfreaks.com/topic/90561-mysql_num_rows-not-a-valid-resource/#findComment-464313 Share on other sites More sharing options...
Barand Posted February 11, 2008 Share Posted February 11, 2008 RTFM mysql_num_rows (PHP 3, PHP 4, PHP 5) mysql_num_rows -- Get number of rows in result Description int mysql_num_rows ( resource result ) Retrieves the number of rows from a result set. This command is only valid for SELECT statements. To retrieve the number of rows affected by a INSERT, UPDATE, or DELETE query, use mysql_affected_rows(). Link to comment https://forums.phpfreaks.com/topic/90561-mysql_num_rows-not-a-valid-resource/#findComment-464315 Share on other sites More sharing options...
cooldude832 Posted February 11, 2008 Share Posted February 11, 2008 logically a num_rows doesn't make sense on an insert. Yes it should return a single affect row on success, but if you have the or die(mysql_error()."<Br /><br />".$q); then it dies if the query fails. If you want to test that the user name isn't already used run a select first and then get the num rows off that. Num_rows is only really useful on updates selects and deletes Link to comment https://forums.phpfreaks.com/topic/90561-mysql_num_rows-not-a-valid-resource/#findComment-464319 Share on other sites More sharing options...
Barand Posted February 11, 2008 Share Posted February 11, 2008 logically a num_rows doesn't make sense on an insert. Yes it should return a single affect row on success, but if you have the or die(mysql_error()."<Br /><br />".$q); then it dies if the query fails. Num_rows is only really useful on updates selects and deletes As the manual states (read my previous post) num_rows is only for select statements. Affected_rows is for queries that do not return a result set (insert, update, delete) And ALL of them can affect multiple rows. Link to comment https://forums.phpfreaks.com/topic/90561-mysql_num_rows-not-a-valid-resource/#findComment-464332 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.