Re: REsource Identifier( PHP_MYSQL)
| From: | David Robley | Date: | Sat, 27 Mar 2004 06:36:59 +0000 |
| Subject: | Re: REsource Identifier( PHP_MYSQL) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-181606@lists.php.net to get a copy of this message | ||
glmlc@hotmail.com (Gimic) wrote in
news:20040327054050.19385.qmail@pb1.pair.com:
> Hey y'all, I'm having problems trying to get the
> MySql_Query() function to return the resource ID when using a $string
> as the argument to pass to it. It returns when I hard code the
> argument but not the string. Any ideas? here is what the function
> looks like:
>
> function GetVals() {
> $db = mysql_connect("localhost", "root");
> $str_Query=("Select * from " . $subject);
>
> mysql_select_db("books",$db);
>
> $result = mysql_query($str_Query);
> echo $result;
>
> }
> but when I use the query:
> $result=mysql_query("Select * from math") it works. Am I setting my
> string up wrong? Because it's not running into any errors when I do
> this.
>
The string $subject is almost certainly empty, as it is not passed as an
argument to the function, nor is it declared global in the function. Try a
little debugging, echoing your query and the output of mysql_error. For
example:
function GetVals() {
$db = mysql_connect("localhost", "root");
$str_Query=("Select * from " . $subject);
mysql_select_db("books",$db);
$result = mysql_query($str_Query);
echo "Query: $str_query<BR>".mysql_error();
echo $result;
}
Then either pass $subject as an argument to the function, or declare it
global within the function.
Lastly, if $string is passed from another script, make sure it is populated
via the GET or POST globals.