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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?