我正在php中构建一个表单,该表单将向所有者发送包含请求的电子邮件,并链接到一个表格,其中表格将显示所有请求。我一直在"阵列"在多项目清单的输出中......这就是我所拥有的
<form>
<input type="checkbox" name="multimedia[]" value="Assessment" />Assessment<br/>
<input type="checkbox" name="multimedia[]" value="elearning module" />E-Learning Module<br />
<input type="checkbox" name="multimedia[]" value="Photography" />Photography<br />
视频拍摄
其他
<?php
$multimedia = array();
echo implode(',', $_POST['multimedia']);
$multimedia_string = implode(',', $multimedia);
?>
//variables in each cell
$variables = array();
$variables['fname'] = $_POST['fname'];
$variables['lname'] = $_POST['lname'];
$variables['email'] = $_POST['email'];
$variables['projectTitle'] = $_POST['projectTitle'];
$variables['$multimedia_string'] = $_POST['$multimedia_string'];
$variables['credentialing'] = $_POST['credentialing'];
$variables['description'] = $_POST['description'];
$variables['results_data_page'] = $results_data_page;
答案 0 :(得分:1)
改变这个:
$variables['$multimedia_string'] = $_POST['$multimedia_string'];
...为:
$variables['multimedia_string'] = implode(',', $_POST['multimedia']);
说明:
PHP将$_POST['multimedia']
解释为数组,因为在[]
之后使用方括号multimedia[]
,因此您可以使用逗号作为分隔符将其内爆并获取字符串返回。
还有其他一些问题,请尝试相反:
<?php
//variables in each cell
$variables = array();
$variables['fname'] = $_POST['fname'];
$variables['lname'] = $_POST['lname'];
$variables['email'] = $_POST['email'];
$variables['projectTitle'] = $_POST['projectTitle'];
$variables['multimedia_string'] = implode(',', $_POST['multimedia']);
$variables['credentialing'] = $_POST['credentialing'];
$variables['description'] = $_POST['description'];
$variables['results_data_page'] = $results_data_page;
?>
的问题:
前三行似乎没有做任何事情。
$multimedia = array(); // never populated
echo implode(',', $_POST['multimedia']);
$multimedia_string = implode(',', $multimedia); // still not populated, so implodes to an empty string.
这里有几件事:
$variables['$multimedia_string'] = $_POST['$multimedia_string'];
PHP变量不以单引号字符串进行插值。换句话说,要将PHP变量从变量名$name
转换为字符串中的值,您需要使用双引号或HEREDOC:
echo "I $emotion you very much.";
$html = <<<EOT
<table>
<tr>
<td>We $emotion camping.</td>
</tr>
</table>
EOT;
所以'$multimedia_string'
只是一个包含美元符号和文本“multimedia_string”的字符串。
另一件事是,似乎没有$_POST
var具有该名称或您想要转换为$multimedia_string
的任何内容。