php - MYSQL Query with String Refer to Value in Database -



php - MYSQL Query with String Refer to Value in Database -

i have mysql query below:

$sourcedata = mysql_fetch_array( mysql_query("select whereclause generaltable id = '1'" ) ); $whereclause = $sourcedata['whereclause'];

in "whereclause" field "generaltable" in database, consist of below text:

where username = '$_session[username]'

then have other query:

$data = mysql_fetch_array( mysql_query("select * usertable $whereclause" ) );

when echo $data['username'], not showing anything.

if re-create value database replace $whereclause working fine, if replace '$_session[username]' 'admin' example, working fine.

how can solve this? need help please.

thank much.

the problem you're having $whereclause string, not evaluated ('$_session[username]' remains is).

you have tell php evaluate string function eval():

$data = mysql_fetch_array( mysql_query( eval("return \"select * usertable $whereclause\";") ) );

php mysql

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -