Forum Moderators: open

Message Too Old, No Replies

mysql + array integration syntax error

help

         

rodriguez1804

10:54 pm on Jul 28, 2008 (gmt 0)

10+ Year Member



I had a previous script where I defined my variables right before I used them in the mysql query, like so:

$tbl_name = "name";
$sql_query = "SELECT * FROM $tbl_name...etc.

Now, I am rewriting the script by using an array to hold all my predefined variables, but I keep on getting a
"mysql_num_rows(): supplied argument is not a valid MySQL result resource" error. What am I doing wrong? Here is the line that causes the error:


$sql_query = "SELECT * FROM $safe[db][tbl_name] WHERE username = '$safe[user][myusername]'";

thanks for any help!

rodriguez1804

9:16 pm on Jul 29, 2008 (gmt 0)

10+ Year Member



well, thanks anyways guys, I ll figure it out

coopster

4:00 pm on Aug 1, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The mysql_num_rows [php.net] function expects a valid result resource and since your query is failing because the syntax is incorrect you are not getting a valid resource handler to pass to the function.

The best way to check the syntax of your query is to dump it to the browser and have a look at the statement. Also, when using array values in strings I tend to stick to the braces syntax:

$sql_query = "SELECT * FROM {$safe['db']['tbl_name']} WHERE username = '{$safe['user']['myusername']}'";