Search
Left Quote    I think there is a world market for maybe five computers.
- Thomas Watson, Chairman of IBM 1943    
Right Quote
 
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply


        Viewing Topic: Resource id #5
  This user is offline  David1159
  Subject: "Resource id #5" Posted: @ 1:08 am on Mar 28 2008   

Member #: 526
Rank: User - (81)
Since: 12/27/07
Posts: 81
From: usa

Working on a small Text base game, thought it would be good for learning more coding.

I keep getting a Resource id #5 when I try to retrieve my data from mysql database.

I've tried htmlspecialchar s(stripslashes( )) with no success. I am trying to grab an integer and display it on the page.

This is my include('page') ;

Code:

<? session_start() ;
include("i nclude/dbc.php& quot;

if($_SESSION['l ogged_in'] == 1) {

$get_money = mysql_query(&qu ot;SELECT `money` FROM `USERS` WHERE `username` = '".$_SESSI ON['username']. "' ";

$_SESSION['mone y'] = $get_money;

}
?>



index.php

Code:

<? session_start( );

if($_SESSION['l ogged_in'] == 1) {

include('includ e/playerdata.ph p');

echo '<a href="incl ude/logout.php& quot;>LOGOUT </a> '.$_SESSION['us ername'].' ';

echo '.htmlspecialch ars(stripslashe s($get_money)). ';

} else {
die('Please <a href="logi n.php>LOGIN HERE</a>' );
}

?>




Coding is simply CST... Combining $hit Together. We make different $hit to run in unison correctly.
    Viewed: 7,994 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Resource id #5" Posted: @ 1:18 am on Mar 28 2008    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

If you disable smilies at the bottom it should help eliminate smilies in your code samples... just an FYI.

Anyways, you could probably write the whole thing like this:
Code:

<?
session_start() ;
include(" include/dbc.php ";

if($_SESSION[' logged_in'] == 1) {

include('inclu de/playerdata.p hp');

$get_money = mysql_query(&q uot;SELECT `money` FROM `USERS` WHERE `username` = '".$_SES SION['username ']."' LIMIT 1");
if(!$get_money ) die(mysql_error ());


while($_SESSION ['money'] = $get_money) {


echo(htmlspecia lchars(stripsla shes($get_money )) . "<BR&g t;<BR>&q uot; . "<a href='include/ logout.php'> ;Logout</a&g t; " . $_SESSION['use rname']);


} else {

die('Please <a href="log in.php>LOGIN HERE</a> ');
}

?>





-bs0d | AllSyntax.com

    Viewed: 7,989 Times | Reply to This | To top
  This user is offline  David1159
  Subject: "re: Resource id #5" Posted: @ 2:20 am on Mar 28 2008    

Member #: 526
Rank: User - (81)
Since: 12/27/07
Posts: 81
From: usa

I tried what you posted, it keep posting Resource id #6 over and over, never ended too on my browser.




Coding is simply CST... Combining $hit Together. We make different $hit to run in unison correctly.

    Viewed: 7,985 Times | Reply to This | To top
  This user is offline  David1159
  Subject: "re: Resource id #5" Posted: @ 2:38 am on Mar 28 2008    

Member #: 526
Rank: User - (81)
Since: 12/27/07
Posts: 81
From: usa

Now I feel like a real idiot, I had it working the first time... I didn't have anything in mysql database for it to display.

I'd rather not combine them, because this include page is going to gather all the players data, and I'd rather have that off of my index.php

Sorry, thanks for the help.



Edited at 02:42:57 am on 03/28/08


Coding is simply CST... Combining $hit Together. We make different $hit to run in unison correctly.

    Viewed: 7,980 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Resource id #5" Posted: @ 2:52 am on Mar 28 2008    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

Yea your call, thats weird. You've got to have something in the database for it to return for sure, but I thought: if(!$get_money) die(mysql_error ()); would have fixed something to that nature.

Sounds like it was an infinite loop. Which is weird too since I said LIMIT 1 in the query, but again maybe not resoureces in the DB contributed to that.

Its acting weird really, I haven't see the error codes you're quoting so its kind of difficult to help, you know. But in the end, I dont think your code will work:

echo '.htmlspecialc hars(stripslash es($get_money)) .';

Im pretty sure you're got to use mysql_fetch_obj ect(); function to return the properties of the row you queried (money column).




-bs0d | AllSyntax.com

    Viewed: 7,975 Times | Reply to This | To top
  This user is offline  David1159
  Subject: "re: Resource id #5" Posted: @ 3:24 am on Mar 28 2008    

Member #: 526
Rank: User - (81)
Since: 12/27/07
Posts: 81
From: usa

No sorry, I might have said it wrong. I had tried 2 codings, first one didn't so anything (which it worked because I had nothing in my db to display). The second one I posted here, I thought it was working because it should a Resource id #5.

Yes the coding to my first post doesn't work. The other coding I didn't show here works.

I'll post the working code if you'd like.




Coding is simply CST... Combining $hit Together. We make different $hit to run in unison correctly.

    Viewed: 7,966 Times | Reply to This | To top
Viewing Page: 1 of 1


1 |

You must be logged in to post on the forums. Login or Register








"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank