Columbo
08-16-2009, 02:20 AM
I need to find a way to use a variable in a WHERE clause.
I have a page with a form that a user inputs a web site name. (for example mysite.com). No http:// or www.
That input is passed to another page using $_POST['domain'];
The other page assigns the user input into a variable called $site by using:
$site=$_POST['domain'];
$query="SELECT webSite, userName, password FROM my_sites WHERE webSite=$site";
$result=mysql_query($query, $db_handle) or die(mysql_error());
...but it flags an error:
Warning: mysql_query() expects parameter 2 to be resource, string given in C:\wamp\www\logins\dosearch.php on line 12
If I type in the name of the web site instead of using the variable $site, it works. It doesn't seem to like the variable. Can anyone tell me if a variable can be used and if so, what would be the syntax?
Thanks
I have a page with a form that a user inputs a web site name. (for example mysite.com). No http:// or www.
That input is passed to another page using $_POST['domain'];
The other page assigns the user input into a variable called $site by using:
$site=$_POST['domain'];
$query="SELECT webSite, userName, password FROM my_sites WHERE webSite=$site";
$result=mysql_query($query, $db_handle) or die(mysql_error());
...but it flags an error:
Warning: mysql_query() expects parameter 2 to be resource, string given in C:\wamp\www\logins\dosearch.php on line 12
If I type in the name of the web site instead of using the variable $site, it works. It doesn't seem to like the variable. Can anyone tell me if a variable can be used and if so, what would be the syntax?
Thanks