I have entered the following query in MySQL:
insert into hospital (name,age) values ('william', 'select * from department where age = $agegrp');
Now I have fetched this value (the sql), and trying to execute it. How can i do this?
I have fetched the select statement into a variable called $var.
$agegrp = "10";
$value = mysql_query ($var) or die ('error');
I only get error so something is wrong with my query that I inserted. How can I solve this?
die( mysql_error() )and then you could see what the error is (I won't spoil the surprise).$var? could you show your complete code if themysql_error()doesn't help you?mysql_*functions in new code. They were removed from PHP 7.0.0 in 2015. Instead, use prepared statements via PDO or MySQLi. See Why shouldn't I use mysql_* functions in PHP? for more information.