Jump to content

I can't figuer this database connect stuff!


bobleny

Recommended Posts

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]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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--];
Link to comment
Share on other sites

[!--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]
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.