duanchi0897 2016-04-08 20:13
浏览 17
已采纳

PHP - 将数据库信息回显为字符串

I am simply trying to echo or print out specific data from a DB into a string (i hope thats the right name), which should be a very simple process as I've done it before. The point is everytime a user inserts information into the database this string echo's or prints out the inserted data.

But for some very odd reason this time around when i try to echo out the data, I literally get this.

enter image description here

Very frustrating. As you can see from the image above i have tried using 2 different ways to do this a variable and a session, but the echo literally just prints it out. I have done this before so i am aware that it is possible. I am just a little lost into how i am meant to achieve this or even better where i went wrong. I know how to do this using a different style of coding, but i am trying to keep everything uniformed (newbie).

  $addon_name = $_SESSION['Add_On_OpName'];
  mysqli_report(MYSQLI_REPORT_INDEX); //overrid a common php nonsense error
  $prod_sel = $dbc->query("SELECT * FROM Add_On WHERE Add_On_OpName = '$addon_name'");
  $prod_sel->data_seek(0);
  while ($output = $prod_sel->fetch_assoc()) {
  $prod_run .= $output['Add_On_OpName'] . $output['Prod_Name'] . $output['Add_On_Price'] . $output['Add_On_Select'] . '<br>';
$addon = $output['Add_On_OpName']; //echo out product name
$_SESSION['Prod_Name'] = $output['Prod_Name']; //echo out product desc
$_SESSION['Add_On_Price'] = $output['Add_On_Price']; //echo out price


echo '
<p>$addon . " " .  $_SESSION["Add_On_Price"]; </p>                    
 ';

My session is started and the php file is connected to the DB. I also have error handling which has not given out any error messages.

  • 写回答

5条回答 默认 最新

  • duancutan4770 2016-04-08 20:17
    关注

    You must do:

    echo "<p>$addon ".$_SESSION["Add_On_Price"]."; </p>";
    

    A string encapsulated into ' is rendered just as it is. Use " to render a string that contains variables. Example:

    $a = 3;
    $a++;
    echo "the result is $a";
    

    will result in the result is 4. On the other hand,

    echo 'the result is $a';
    

    gives the result is $a.

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

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog