willwill100 Posted March 21, 2006 Share Posted March 21, 2006 from this code:[code]$namen = mysql_query("SELECT * FROM `$compl` WHERE `Name`='$name'");echo ("<pre>" . $namen . "</pre>");[/code]i get the <pre> displaying:[code]Resource id #6[/code]what is the reason for this? Quote Link to comment https://forums.phpfreaks.com/topic/5438-resource-id-6-error/ Share on other sites More sharing options...
kenrbnsn Posted March 21, 2006 Share Posted March 21, 2006 The mysql_query() function returns a pointer to the rows selected not the rows. To get individual rows, you need to use one of the mysql_fetch functions, usually in a loop.Ken Quote Link to comment https://forums.phpfreaks.com/topic/5438-resource-id-6-error/#findComment-19433 Share on other sites More sharing options...
willwill100 Posted March 21, 2006 Author Share Posted March 21, 2006 ok, ive ammended my code but i still get a negative result:[code]////if their name does not already exist in the REAL table, insert it////$q = "SELECT COUNT(*) FROM `$compl` WHERE `Sail Number`='$snum'";echo ("<pre>" . $q . "</pre>");$rs = mysql_query($q) or die('Problem with query: ' . $q . '<br>' . mysql_error());if (mysql_fetch_assoc($rs)==0){ $b = "INSERT INTO `$compl` ( `Name` , `Sail Number` , `Class`) VALUES ( '$name', '$snum', '$boattype')"; }else{echo ("<br>No user updated!");}[/code]I have inputted $q into phpmyadmin and a value of "0" is returned, why then is the "if statement" taken to be false and "No user updated!" outputted?? Quote Link to comment https://forums.phpfreaks.com/topic/5438-resource-id-6-error/#findComment-19441 Share on other sites More sharing options...
redbullmarky Posted March 21, 2006 Share Posted March 21, 2006 on this line:[code]if (mysql_fetch_assoc($rs)==0){[/code]you're checking if an entire array equals 0. even if there are no rows, it still wont return the number 0.what you need is[code]if (mysql_num_rows($rs) == 0) {[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5438-resource-id-6-error/#findComment-19442 Share on other sites More sharing options...
willwill100 Posted March 21, 2006 Author Share Posted March 21, 2006 okay that makes sense but i still get the error.any ideas, im really stuck on how to get my table to check if there is already a user in it and enter one if the user is not in the table..... Quote Link to comment https://forums.phpfreaks.com/topic/5438-resource-id-6-error/#findComment-19447 Share on other sites More sharing options...
keeB Posted March 21, 2006 Share Posted March 21, 2006 [!--quoteo(post=357078:date=Mar 21 2006, 08:31 PM:name=WillWill)--][div class=\'quotetop\']QUOTE(WillWill @ Mar 21 2006, 08:31 PM) [snapback]357078[/snapback][/div][div class=\'quotemain\'][!--quotec--]okay that makes sense but i still get the error.any ideas, im really stuck on how to get my table to check if there is already a user in it and enter one if the user is not in the table.....[/quote][code]<?php$q = "SELECT COUNT(*) FROM `$compl` WHERE `Sail Number`='$snum'";$result = mysql_query($q); if ( mysql_num_rows($query) == 0 ) { $q2 = "INSERT INTO `$compl` ( `Name` , `Sail Number` , `Class`) VALUES ( '$name', '$snum', '$boattype')"; mysql_query($q2); } //more code here or whatever?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5438-resource-id-6-error/#findComment-19450 Share on other sites More sharing options...
craygo Posted March 21, 2006 Share Posted March 21, 2006 why not just do this[code]////if their name does not already exist in the REAL table, insert it////$q = "SELECT * FROM `$compl` WHERE `Sail Number` = '$snum'";$rs = mysql_query($q) or die('Problem with query: ' . $q . '<br>' . mysql_error()); $num_rows = mysql_num_rows($rs);if ($num_rows == 0){ $b = "INSERT INTO `$compl` ( `Name` , `Sail Number` , `Class`) VALUES ( '$name', '$snum', '$boattype')"; }else{echo ("<br>No user updated!");}[/code]Ray Quote Link to comment https://forums.phpfreaks.com/topic/5438-resource-id-6-error/#findComment-19452 Share on other sites More sharing options...
willwill100 Posted March 21, 2006 Author Share Posted March 21, 2006 thats great, thanx for the help guys! Quote Link to comment https://forums.phpfreaks.com/topic/5438-resource-id-6-error/#findComment-19459 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.