dongyu3659 2014-08-06 12:54
浏览 35
已采纳

php sendmail表单中的变量

im a beginner in php / mysql so go easy on me :)

I made a very basic php order form for our work which has lots of dropdown boxes. This submits the results via an email using sendmail in php.

Now im trying to make it dynamic using a sql database.

I have the form set up using the sql and php, but my problem lies in the sending of the dynamically generated data.

I have all the variables available by using this line

extract($_POST['orderdetails'], EXTR_SKIP);

the variables end up as $vanilla00, $vanilla06, $vanilla11, etc...

So now I have this code to create the table using these variables

while($row = mysql_fetch_array($resultbline))

{$message   .="<tr><td>" 
. $row['prod_name'] 
. "</td><td>&nbsp;</td><td></td>
<td>$" . $row['prod_selectname'] . "0</td>
<td>$" . $row['prod_selectname'] . "6</td>
<td>$" . $row['prod_selectname'] . "11</td>
<td>$" . $row['prod_selectname'] . "18</td>
<td>$" . $row['prod_selectname'] . "t</td>
<td>$" . $row['prod_selectname'] . "24</td>
<td>$" . $row['prod_selectname'] . "36</td>" ;
} 

The prod_selectname is taken from the database and in this instance will be vanilla, so the final table ends up reading

while($row = mysql_fetch_array($resultbline))

{$message   .="<tr><td>" 
. $row['prod_name'] 
. "</td><td>&nbsp;</td><td></td>
<td>$vanilla0</td>
<td>$vanilla6</td>
<td>$vanilla11</td>
<td>$vanilla18</td>
<td>$vanillat</td>
<td>$vanilla24</td>
<td>$vanilla36</td>" ;
}

the problem is that the resulting email shows the variable name (ie vanilla18) instead of treating it as a variable.

Am I missing some . { ( [ or other code somewhere ?

Sorry to be so thorough, but I dont know how else to explain it.

Thanks in advance

  • 写回答

2条回答 默认 最新

  • dongqigu0429 2014-08-06 13:03
    关注

    That's because you are concatenating $row['prod_selectname'] as string. Before you echo each variable you need to name it dinamically, like this:

    $var_name = $row['prod_selectname'] . "0";
    

    When you echo the variable, it will be like this:

    "<td>" . echo $$var_name . "</td>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#lua#的问题,请各位专家解答!
  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥15 人在外地出差,速帮一点点