ZaphodQB Posted June 4, 2008 Share Posted June 4, 2008 Running PHP Version 5.2.5 case "deleteprefix"; $Query = "update prefixes set status = -1 where id = '107' AND status > -1"; $Result = mysql_query ($Query, $Connection) or die("Prefix update query failed : ".mysql_error($Connection)); $updateCounter=mysql_affected_rows($Result); echo "updateCounter = $updateCounter"; if($updateCounter){change_counter("vails","prefixcount",1,$tempVailData['id']);} break; There are no errors being returned. CREATE TABLE `prefixes` ( `id` bigint(20) unsigned NOT NULL auto_increment, `vail` bigint(20) unsigned NOT NULL default '0', `text` varchar(32) collate latin1_general_ci NOT NULL default '', `status` tinyint(4) NOT NULL default '0', `key` varchar(32) collate latin1_general_ci NOT NULL default '', PRIMARY KEY (`id`), KEY `text` (`text`), KEY `vail` (`vail`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=118 ; The query sets a status column in the prefixes table to -1 for the row with the id(primary key) of 107. This works and I can look in the database and see that the column has been changed from a 1 to a -1. But the mysql_affected_rows($Result) statement does not appear to be returning a value into the $updateCounter (flag) veriable. Output from the echo is "updateCounter =" (nothing in there) So the line that is supposed to call the function change_counter() never calls. What kind of simple misunderstanding am I operating under here, that is causing this simple step to fail? Thanks for your time. Link to comment https://forums.phpfreaks.com/topic/108647-solved-mysql_affected_rows-not-returning-affected-row-count/ Share on other sites More sharing options...
hvle Posted June 4, 2008 Share Posted June 4, 2008 mysql_affected_rows([$database_link]) ; I think it won't work correctly because you passed in $Result, which is not a database link. try $updateCounter = mysql_affected_rows($Connection); or maybe just $updateCounter = mysql_affected_rows(); Link to comment https://forums.phpfreaks.com/topic/108647-solved-mysql_affected_rows-not-returning-affected-row-count/#findComment-557184 Share on other sites More sharing options...
ZaphodQB Posted June 4, 2008 Author Share Posted June 4, 2008 Thank you I knew I was doing something stupid, but my brain is fried and I could not figure out what it was. I had to pas it the Connection resource! Thanks works like it's suposed to now! Link to comment https://forums.phpfreaks.com/topic/108647-solved-mysql_affected_rows-not-returning-affected-row-count/#findComment-557186 Share on other sites More sharing options...
PFMaBiSmAd Posted June 4, 2008 Share Posted June 4, 2008 The original code was probably generating a php error. When developing php code or debugging php code, always set php error_reporting to E_ALL and display_errors on to get php to help you. Link to comment https://forums.phpfreaks.com/topic/108647-solved-mysql_affected_rows-not-returning-affected-row-count/#findComment-557187 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.