bobleny Posted May 30, 2006 Share Posted May 30, 2006 I don't belive I have this correct. all it says on the page is Resource id #4.so what is wrong with this code?[code]mysql_connect('db4.awardspace.com:3306',$username,$password);mysql_select_db($database);$forumpass = mysql_query("SELECT forumpass FROM forum_users WHERE forumname = '" . $inputname . "'");echo $forumpass;[/code] Quote Link to comment Share on other sites More sharing options...
fenway Posted May 30, 2006 Share Posted May 30, 2006 There's nothing wrong with that -- mysql_query() returns a PHP "resource", better known as a recordset. If you want do anything with it, you need to fetch the information in each of the records -- mysql_fetch_assoc() is a good way to do this. The PHP manual has plenty of good examples. Quote Link to comment Share on other sites More sharing options...
bobleny Posted May 30, 2006 Author Share Posted May 30, 2006 Now all it says is, "Array". All the examples that I've seen have the mysql_fetch_assoc() in a while loop. I would think that what I have would work? It fetches the $query results and assigns it as $forumpass, right?[!--coloro:#000099--][span style=\"color:#000099\"][!--/coloro--]$inputname[!--colorc--][/span][!--/colorc--] = [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]'Bob Leny'[!--colorc--][/span][!--/colorc--];[!--coloro:#000099--][span style=\"color:#000099\"][!--/coloro--]mysql_connect[!--colorc--][/span][!--/colorc--]([!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]'db4.awardspace.com:3306'[!--colorc--][/span][!--/colorc--],[!--coloro:#000099--][span style=\"color:#000099\"][!--/coloro--]$username[!--colorc--][/span][!--/colorc--],[!--coloro:#000099--][span style=\"color:#000099\"][!--/coloro--]$password[!--colorc--][/span][!--/colorc--]);[!--coloro:#000099--][span style=\"color:#000099\"][!--/coloro--]mysql_select_db[!--colorc--][/span][!--/colorc--]([!--coloro:#000099--][span style=\"color:#000099\"][!--/coloro--]$database[!--colorc--][/span][!--/colorc--]);[!--coloro:#000099--][span style=\"color:#000099\"][!--/coloro--]$query[!--colorc--][/span][!--/colorc--] = [!--coloro:#000099--][span style=\"color:#000099\"][!--/coloro--]mysql_query[!--colorc--][/span][!--/colorc--]([!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]"SELECT forumpass FROM forum_users WHERE forumname = '"[!--colorc--][/span][!--/colorc--] . [!--coloro:#000099--][span style=\"color:#000099\"][!--/coloro--]$inputname[!--colorc--][/span][!--/colorc--] . [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]"'"[!--colorc--][/span][!--/colorc--]);[!--coloro:#000099--][span style=\"color:#000099\"][!--/coloro--]$forumpass[!--colorc--][/span][!--/colorc--] = [!--coloro:#000099--][span style=\"color:#000099\"][!--/coloro--]mysql_fetch_assoc[!--colorc--][/span][!--/colorc--]([!--coloro:#000099--][span style=\"color:#000099\"][!--/coloro--]$query[!--colorc--][/span][!--/colorc--]);[!--coloro:#009900--][span style=\"color:#009900\"][!--/coloro--]echo[!--colorc--][/span][!--/colorc--] [!--coloro:#000099--][span style=\"color:#000099\"][!--/coloro--]$forumpass[!--colorc--][/span][!--/colorc--]; Quote Link to comment Share on other sites More sharing options...
AndyB Posted May 30, 2006 Share Posted May 30, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]It fetches the $query results and assigns it as $forumpass, right?[/quote] Yes, an [b]array[/b] named $forumpass. So ...[code]mysql_connect('db4.awardspace.com:3306',$username,$password);mysql_select_db($database);$query = mysql_query("SELECT forumpass FROM forum_users WHERE forumname = '" . $inputname . "'");$row = mysql_fetch_assoc($query);$forumpass = $row['forumpass'];echo $forumpass;[/code] Quote Link to comment Share on other sites More sharing options...
fenway Posted May 31, 2006 Share Posted May 31, 2006 In general, though, you should probably always have this in a while loop anyway. Quote Link to comment 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.