Jump to content

mysql_num_rows not a valid resource?


darkfreaks

Recommended Posts

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

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().

 

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.