dpbz14739 2015-01-11 23:00
浏览 55
已采纳

使用存储在mysql文本中的变量

i have a situation where i need to be able to store variables from mysql. the pages i am creating are dynamic and contain different user data, what im chasing is the following

//stored in user database
$firstname = "BOB"
$lastname = "MARLEY"

//how i want th content from a mysql database to display in html
hello my name is BOB MARLEY

//how it displays at the moment
hello my name is $firstname $lastname

i cant seem to work it out at all

this is my current database code

<?php
        $firstname= "BOB";
        $lastnamename= "marley";
    $get_content= mysqli_query($con,"SELECT * FROM tbl_forms_content WHERE forms_content_formid='1' LIMIT 1 ");
    while($found_content = mysqli_fetch_array($get_content))
    { 
        echo $found_content['forms_content_content'];
    }   
?>  

any help is greatly apreciated

  • 写回答

2条回答 默认 最新

  • dongtou5557 2015-01-11 23:07
    关注

    The right solution is to use a template library. To do what you're trying, you need to use eval:

    $firstname= "BOB";
    $lastname= "marley";
    while($found_content = mysqli_fetch_array($get_content))
    { 
        eval ('echo "' . $found_content['forms_content_content'] . '";');
    }
    

    This is very dangerous. If the database contains values that can be set by the user, they could execute any PHP code from it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制