0

Hi all,

I've looked through this forum for some hours and am absolutely unable to fix my problem; no matter what I do.

I'm trying to pass a PHP variable as part of a MYSQL query like so:

$id = $_GET["bodyid"];

$blog = getEntries("SELECT `Articlebody` FROM `Blog` WHERE id ='$id'");

function getEntries($query) {
  $connection = mysql_open();
    
	echo $query;
  
  $result = @ mysql_query($query, $connection)
      or showerror();
  $blog = array();
  while ($row = mysql_fetch_array($result)) {
      $blog[] = $row;
  }
  mysql_close($connection)
      or showerror();
  return $blog;
}

What is happening is that the query is returning no results because the variable is not being recognized for whatever reason.

The echo statement in the getEntries method is returning :

SELECT `Articlebody` FROM `Blog` WHERE id =''

Could somebody point me in the right direction?

Thanks.

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by warren88
0

Print and check whether your page is getting the values properly or not, by keeping following code in the begining of your page.

echo "<pre>";
print_r($_GET);
echo "</pre>";

Edited by urtrivedi: n/a

0

Thanks for the speedy reply.

When I do that, it echos

Array
(
[blogid] => 3
)

1

Change your code from
Your code should be changed from

$blog = getEntries("SELECT `Articlebody` FROM `Blog` WHERE id ='$id'");

to

$blog = getEntries("SELECT `Articlebody` FROM `Blog` WHERE id ='".$id."'");
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.