-1

I was try to loop PHP CODE data from MYSQL database, but it looks different when it's echo'd out.

HERE IS MY PHP CODE:

<?php

mysql_connect("localhost","root","");
mysql_select_db("myweb");


?>

<table width="100%" border="1">
<?php
$query=mysql_query("SELECT * FROM right_widgets ORDER BY right_widgets_id ASC");
while($rows2=mysql_fetch_assoc($query))
{ 
    $right_widgets_id=$rows2['right_widgets_id'];
    $func_name=$rows2['func_name'];
    $active_status=$rows2['active_status'];

?>
  <tr>
    <td><?php echo $func_name; ?></td>
    </tr>
<?php
}
?>
  </table>

HERE IS MY SQL CODE:

--
-- Database: `myweb`
--

-- --------------------------------------------------------

--
-- Table structure for table `right_widgets`
--

CREATE TABLE IF NOT EXISTS `right_widgets` (
  `right_widgets_id` int(11) NOT NULL,
  `func_name` text NOT NULL,
  `active_status` text NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `right_widgets`
--

INSERT INTO `right_widgets` (`right_widgets_id`, `func_name`, `active_status`) VALUES
(1, '<?php get_search_engine(); ?>', 'true'),
(2, '<?php get_clock(); ?>', 'true'),
(3, '<?php get_virtual_nav_menu(); ?>', 'false'),
(4, '<?php get_non(); ?>', 'false');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `right_widgets`
--
ALTER TABLE `right_widgets`
  ADD PRIMARY KEY (`right_widgets_id`);

--
-- AUTO_INCREMENT for dumped tables
--

Problem is when it run it looks like this:

enter image description here

But I need this:

<?php get_search_engine(); ?>
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Asif Uz Zaman
  • 337
  • 1
  • 14
  • You want that PHP code from the db to be executed? That's not possible unless you use `eval()` (**DON"T USE EVAL**), or write the retrieved code out to a file and then include/require it... And PHP and mysql will *NOT* comment-out code for you. if it's commented-out in your output, then it went into the database as a comment. – Marc B Jun 12 '15 at 16:46
  • 2
    if you still want to output it as string instead of function then use `=str_replace(array('<'),'<','') ?>` – ɹɐqʞɐ zoɹǝɟ Jun 12 '15 at 16:55
  • @castis i would feel motivated to educate my self, as should the OP. – r3wt Jun 12 '15 at 16:57
  • @FerozAkbar Where I putthis code? – Asif Uz Zaman Jun 12 '15 at 16:59
  • 1
    If you can, you should [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) [statements](http://php.net/manual/en/pdo.prepared-statements.php) instead, and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jun 12 '15 at 17:01
  • 1
    @AsifUzZaman here `` like this `` – ɹɐqʞɐ zoɹǝɟ Jun 12 '15 at 17:04
  • @FerozAkbar: Ok Sir wait. – Asif Uz Zaman Jun 12 '15 at 17:05
  • @FerozAkbar: Yes it is working. Thank you – Asif Uz Zaman Jun 12 '15 at 17:08
  • @AsifUzZaman okay, but what is purpose of showing it like that o_O – ɹɐqʞɐ zoɹǝɟ Jun 12 '15 at 17:10
  • @Squeegy Yes Sir it is working, like I want, Thank you. – Asif Uz Zaman Jun 12 '15 at 17:15

1 Answers1

1

Please modify your table value ok, your code in sql

INSERT INTO `right_widgets` (`right_widgets_id`, `func_name`, `active_status`) VALUES
(1, '<?php get_search_engine(); ?>', 'true'),
(2, '<?php get_clock(); ?>', 'true'),
(3, '<?php get_virtual_nav_menu(); ?>', 'false'),
(4, '<?php get_non(); ?>', 'false');

That's mean you table cols name is func_name and value is <?php get_search_engine(); ?> ok, Please modify the value like this get_search_engine(); remove all of <?php ?> this I hope that will work. Thank you.

Softbazz
  • 202
  • 1
  • 9