Page 1 of 1

Help with Databases and strings

Posted: Sat Aug 22, 2009 10:50 am
by satory
Hi, the following is my code:

Code: Select all

<?php
$con = mysql_connect('localhost', "admin","admin");
 
$db_selected = mysql_select_db('forum', $con);
 
$stringName = $_GET['name']; //Get forum users name
 
//Get the users Rank from the phpbb users DB  
$query1 = sprintf("SELECT user_rank FROM phpbb_users WHERE username_clean = '%s'", mysql_real_escape_string($stringName));
$resDepRank = mysql_query($query1,$con);
echo $resDepRank;
 
//Get the users Rank image from the phpbb_ranks DB
$DepRank=mysql_query("SELECT rank_image FROM phpbb_ranks WHERE rank_id='$resDepRank'", $con);
echo $DepRank;
 
?>
and this is the current output:
Resource id #3Resource id #4
when I want it to be
3rank1.png
where "3" is a numerical value, the rank id number from a database and "rank1.png" is a string taken from another table.

How do I change the Resource id #3 to be what I want?

oh and the database is correct with the information that I need, im not sure where this resource id thing is coming from?

Re: Help with Databases and strings

Posted: Sat Aug 22, 2009 11:11 am
by Eran
You should read the documentation on mysql_query() - http://us2.php.net/manual/en/function.mysql-query.php
It returns a resource to be passed to one of several retrieval functions such as mysql_fetch_assoc()

Re: Help with Databases and strings

Posted: Sat Aug 22, 2009 12:07 pm
by satory
Thank you very much.

Re: Help with Databases and strings

Posted: Sat Aug 22, 2009 1:13 pm
by satory
Just another quick question, rather than start a whole new thread on it....

I have obtained "rank1.png" from the table it was in, and I then added that to a file path string, giving me on my local server
How do I get the image to show on the screen?

Code: Select all

//Get the users Rank image from the phpbb_ranks DB
$resQuery2 = mysql_query("SELECT rank_image FROM phpbb_ranks WHERE rank_id='$resDepRank'", $con);
$ResultRank2 = mysql_fetch_assoc($resQuery2);
$DepRank = $ResultRank2["rank_image"];
 
//Insert the address of the rank image
$str_Rank = "http://localhost/Forum/images/ranks/" . $DepRank; 
$img_Rank = imageCreateFromPNG($str_Rank);
 
ImagePng ($img_Rank); 
 
I've had no luck trying this way.

Re: Help with Databases and strings

Posted: Sat Aug 22, 2009 1:35 pm
by jackpf
1. What do you see in the browser?
2. Do you have errors turned on?
3. You could try sending an image/png content type header.


:)

Re: Help with Databases and strings

Posted: Sat Aug 22, 2009 1:39 pm
by satory
Sorry, I wasn't descriptive at all about my problem :oops:


Yes I'm using the image content header at the top of the file, and when I load the page it only shows a blank, empty image box.

How do you mean errors turned on? Its only my second day of exploring php properly, so you'll have to excuse me. I'm using notepad++ to code then uploading the file onto a local server while I mess about and test it.

Re: Help with Databases and strings

Posted: Sat Aug 22, 2009 1:50 pm
by jackpf
Try putting this at the top of the script:

Code: Select all

ini_set('display_errors', E_ALL);
And just to make sure, you are looking at the actual script right, not through an <img> tag? :)

Re: Help with Databases and strings

Posted: Sat Aug 22, 2009 2:02 pm
by satory
:) Yeah Im only looking at it through the browser's address bar, and not through any img tags...

No errors, or anything else out of the ordinary. I know the file exists as I threw it there this morning. and I've used "echo" to make sure that the file name is whats coming out of the query.

Im going to include the whole script, its not much.

Code: Select all

<?php
ini_set('display_errors', E_ALL);
Header ("Content-type: image/png");
$con = mysql_connect('localhost', "admin","admin");
 
$db_selected = mysql_select_db('forum', $con);
 
//Get forum users name
$stringName = $_GET['name']; 
 
 
//Get the users Rank from the phpbb users DB  
$query1 = sprintf("SELECT user_rank FROM phpbb_users WHERE username_clean = '%s'", mysql_real_escape_string($stringName));
$resQuery1 = mysql_query($query1,$con);
$ResultRank = mysql_fetch_assoc($resQuery1);
$resDepRank = $ResultRank["user_rank"];
 
//Get the users Rank image from the phpbb_ranks DB
$resQuery2 = mysql_query("SELECT rank_image FROM phpbb_ranks WHERE rank_id='$resDepRank'", $con);
$ResultRank2 = mysql_fetch_assoc($resQuery2);
$DepRank = $ResultRank2["rank_image"];
 
//Insert the address of the rank image
$str_Rank = 'http://localhost/Forum/images/ranks/' . $DepRank; 
$img_Rank = imageCreateFromPNG($str_Rank);
 
 
mysql_close($con);
ImagePng ($img_Rank); 
ImageDestroy ($img_Rank);
?>

Re: Help with Databases and strings

Posted: Sat Aug 22, 2009 2:14 pm
by jackpf
Well, your script works.

I'd say it was something to do with the image.

What does $str_Rank contain?


This is rather odd...definitely no errors?

Re: Help with Databases and strings

Posted: Sat Aug 22, 2009 2:31 pm
by satory
$str_Rank contains the path to the image, in this case:

http://localhost/Forum/images/ranks/rank1.png

Re: Help with Databases and strings

Posted: Sat Aug 22, 2009 2:33 pm
by jackpf
And that image definitely exists?


I must admit, I'm a bit lost on this one. Sorry :?

Re: Help with Databases and strings

Posted: Sat Aug 22, 2009 2:38 pm
by satory
Yeah that image exists :(

Thanks for all your help so far!

Re: Help with Databases and strings

Posted: Sun Aug 23, 2009 5:08 am
by jackpf
Right...last stab.

Try commenting out the header('Content-Type..... line. Do you get any errors now?