Jump to content


Photo

I can't figuer this database connect stuff!


  • Please log in to reply
4 replies to this topic

#1 bobleny

bobleny
  • Members
  • PipPipPip
  • Advanced Member
  • 429 posts

Posted 30 May 2006 - 03:02 AM

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?

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;

-- www.firemelt.net --
First do me a favor and read this: JavaScript is NOT Java - Then read this: www.php.net - When your done with that, read this Topic
After that, floors open. I and anyone else will be MORE than happy to answer YOUR query! [Topic Solved]
Cheer up, the worst has yet to come...

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 30 May 2006 - 05:02 AM

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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 bobleny

bobleny
  • Members
  • PipPipPip
  • Advanced Member
  • 429 posts

Posted 30 May 2006 - 10:53 AM

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--];
-- www.firemelt.net --
First do me a favor and read this: JavaScript is NOT Java - Then read this: www.php.net - When your done with that, read this Topic
After that, floors open. I and anyone else will be MORE than happy to answer YOUR query! [Topic Solved]
Cheer up, the worst has yet to come...

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 30 May 2006 - 11:18 AM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]It fetches the $query results and assigns it as $forumpass, right?[/quote]
Yes, an array named $forumpass. So ...

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;

Legend has it that reading the manual never killed anyone.
My site

#5 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 31 May 2006 - 06:34 AM

In general, though, you should probably always have this in a while loop anyway.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users