2016-04-08 20:13
浏览 16

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'");
  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;
    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.

    解决 无用
    打赏 举报

相关推荐 更多相似问题