# Passing a variable into php function mysql query

**URL:** <https://forum.kirupa.com/t/passing-a-variable-into-php-function-mysql-query/315282>\
**Category:** programming\
**Created:** [October 21, 2010, 9:16pm UTC](https://forum.kirupa.com/t/passing-a-variable-into-php-function-mysql-query/315282 "2010-10-21T21:16:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![daveyourself](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@daveyourself](https://forum.kirupa.com/u/daveyourself)\
**Post date:** [October 21, 2010, 9:16pm UTC](https://forum.kirupa.com/t/passing-a-variable-into-php-function-mysql-query/315282/1 "2010-10-21T21:16:38Z")

</div>

I’m trying to pass a variable from within a swf to a php service to get some crap out of the db.

when I do this:

```php
function getProjectThumbs()
{
	$sql = 'SELECT `project_display` FROM `tbl_images` WHERE locate( \'1\', project_id ) ORDER BY `project_displayid`';
	return mysql_query($sql);
}

```

works totally fine, but when I remove the hardcoded item in

```php
WHERE locate( \'1\', project_id )

```

and replace it with

```php
WHERE locate( \'$var\', project_id )

```

to become this

```php
function getProjectThumbs($var)
{
	$sql = 'SELECT `project_display` FROM `tbl_images` WHERE locate( \'$var\', project_id ) ORDER BY `project_displayid`';
	return mysql_query($sql);
}

```

I get no results. can I not pass a variable this way? any help is greatly appreciated!
