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

 

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.