...

View Full Version : Resolved Variables in MYSQL query in imagestring



ItsNotRudy
11-02-2009, 05:19 AM
Hey,

I am making a signature service for a group of peers where they will put

www.mydomain.com/sig.php?id=1[img] in their signature. The id=1 is supposed to fetch the information for the row where id=1, displaying the fields associated.

Here's the code:


<?
$db_host = "localhost";
$db_user = "signatures";
$db_pass = "******";
$db_name = "signatures";
$db = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die ("Cannot Connect To Database");

$id = $_GET['id'];


$query = 'SELECT `name` FROM `information` WHERE id = '$id''
$result = mysql_query($query);


header("Content-type: image/gif");
$im = imagecreatefromgif("sig.gif");
$color = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 5, 200, 1, $result, $color);
imagegif($im);
imagedestroy($im);
?>

The issue seems to be here, but ofcourse I am not totally sure.


$query = 'SELECT `name` FROM `information` WHERE id = '$id''
$result = mysql_query($query);

I've tried like 10 different queries, no ', slashes and whatnot. No result, different weird messages printed on my picture ("Resource ID #2" and "Array"). They all output junk I can't use. What I need is for it to output the "name" field associated to id 1 in the database if I type www.yourdomain.com/sig.php?id=1

If you wish to try out the code, try using this image for optimal testing since that's my planned size:

[IMG]http://downloads.zero-sum.nl/signatures/gifsig/sig.gif

Oh btw, rendering the ID number received by the GET is properly onto the picture when I put the variable in the imagestring.

PappaJohn
11-02-2009, 06:09 AM
$query = 'SELECT `name` FROM `information` WHERE id = '$id''
$result = mysql_query($query);
mysql_query returns a Resource identifier, as evidenced by your Resource ID#2 'junk'

You need to use this to retrieve the records you request. ie:


$query = 'SELECT `name` FROM `information` WHERE id = '$id''
$result = mysql_query($query);

if ($result)
{
$row = mysql_fetch_assoc($result);
echo $row['name']; // echo it or put it in a variable for later use
}

ItsNotRudy
11-02-2009, 02:32 PM
Thanks, I resolved it later that night though, this is what I ended up with :)


<?php
$db_host = "localhost";
$db_user = "signatures";
$db_pass = "******";
$db_name = "signatures";
$db = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die ("Cannot Connect To Database");

$id = $_GET['id'];
$id = stripslashes($id);
$id = mysql_real_escape_string($id);



if (is_numeric($id)) {
$query = "SELECT `name` FROM `information` WHERE id = $id";
$result = mysql_query($query);

if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_array($result);

header("Content-type: image/gif");
$im = imagecreatefromgif("sig.gif");
$color = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 5, 200, 1, $row['name'], $color);
imagegif($im);
imagedestroy($im);
}
}
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum