MySQL Error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

MySQL Error

Post by manojsemwal1 »

Hai Iam facing a problem with this mysql query ............

$sqlinsert="insert into quitstudents value('$regdid','$subjectid','$remarks','L','$cdate')";
echo $sqlinsert;
$rs=mysql_query($sqlinsert) or die("Error: ". mysql_error(). " with query ". $sqlinsert);
$countinsert=mysql_num_rows($sqlinsert);


data is insert into database but giving error.
insert into quitstudents value('8009','4','fgf','L','2010-01-20')
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/iiewscom/public_html/PHP/ClientEntry/quitstudententry.php on line 41
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: MySQL Error

Post by requinix »

mysql_num_rows is only good for SELECT queries. You want mysql_affected_rows.
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

Re: MySQL Error

Post by manojsemwal1 »

Thanks for your reply

its also giving same error........

Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/iiewscom/public_html/PHP/ClientEntry/quitstudententry.php on line 62
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: MySQL Error

Post by Eran »

You need to put the link resource inside mysql_affected_rows, not the query itself. Just run it without parameters in the function (as a quick look in the manual link tsairis provided would have made this obvious)
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

Re: MySQL Error

Post by manojsemwal1 »

Thanks........

ya without parameter its run fine but if we are execute more than one query than what we have to do.

like here
$sqlinsert=mysql_query("insert into quitstudents values('$regdid','$subjectid','$remarks','$cdate','L')");
$sqlregdup=mysql_query("update studentregdtb set Approval='L' where RegdId='$regdid'");

$countinsert=mysql_affected_rows();

this mysql_affected_rows() will return which query last query or frist query.

Thanks
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: MySQL Error

Post by Eran »

It will always return a count for the last query ran with the current connection. Run it between the queries and store the results in a variable.
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

Re: MySQL Error

Post by manojsemwal1 »

Thanks For your valuable reply ...................


thank you very much....................
Post Reply