我正在构建一个简单的工具,它将根据HTML表单输入组装一个字符串。
但是,两个变量没有按预期被拉入字符串。
以下是HTML表单:
<form action="stringmaker.php" method="post">
<label for="subline">Subject line:</label>
<input type="text" id="subline" name="subline" size="30" /><br /><br />
<label for="emailtype">Email Type</label>
<select name="emailtype">
<option value="advocacy" selected>Advocacy</option>
<option value="fundraising">Fundraising</option>
<option value="newsletter">Newsletter</option>
<option value="event">Event</option>
<option value="cultivation">Cultivation</option>
</select><br /><br />
<label for="campaign">Campaign</label>
<select name="campaign">
<option value="campaign1" selected>Campaign 1</option>
<option value="campaign2" selected>Campaign 2</option>
<option value="campaign3" selected>Campaign 3</option>
<option value="campaign4" selected>Campaign 3</option>
</select>
<h3>Audience Information</h3>
<label for="audiencetype">Audience Type</label>
<select name="audiencetype">
<option value="noaudiencetype" selected>None</option>
<option value="interestgroup">Interest Group</option>
<option value="donors">Donors</option>
<option value="actiontakers">Action-Takers</option>
</select><br /><br />
<label for="geo">Audience Geography</label>
<select name="geo">
<option value="national" selected>National</option>
<option value="state">State</option>
<option value="district">District</option>
<option value="city">City</option>
</select><br /><br />
<label for="statename">State</label>
<select name="statename">
<option value="ak" selected>Alaska</option>
<option value="al">Alabama</option>
<option value="az">Arizona</option>
<option value="dc">Washington, D.C.</option>
</select><br /><br />
<input type="submit" value="Go" name="submit" />
这是PHP:
<?php
$subline = $_POST['subline'];
$emailtype = $_POST['emailtype'];
$campaign = $_POST['campaign'];
$audiencetype = $_POST['audiencetype'];
$geo = $_POST['geo'];
$statename = $_POST['statename'];
echo "<p>Here's your string!<br>";
echo $subline,"|",$emailtype,"|",$campaign,"|",$audiencetype,"|",$geo,"|",$statename;
?>
输出缺少第一个($subline
)和第五个($geo
)变量,我无法弄清楚与这些变量有什么不同。
感谢您的帮助。
答案 0 :(得分:1)
修改强>
就目前而言,点和逗号都可以接受,我的错误
您的表单缺少</form>
标记,至少缺少最初发布的代码。
在我的测试中,所有内容都得到了正确的回应。
我唯一可以解释为什么$subline
是空的,是因为它还没有被填满。其他一切都会结束。
我还注意到您还拥有selected
<option value="campaign1" selected>Campaign 1</option>
<option value="campaign2" selected>Campaign 2</option>
<option value="campaign3" selected>Campaign 3</option>
<option value="campaign4" selected>Campaign 3</option>
旁注:你有2x Campaign 3
,但这不会影响任何事情。
应该只有一个。
<option value="campaign1" selected>Campaign 1</option>
<option value="campaign2">Campaign 2</option>
<option value="campaign3">Campaign 3</option>
<option value="campaign4">Campaign 3</option>
(将其修改为广告系列4)
<option value="campaign1" selected>Campaign 1</option>
<option value="campaign2">Campaign 2</option>
<option value="campaign3">Campaign 3</option>
<option value="campaign4">Campaign 4</option>
我的一个测试结果:
Here's your string! test|fundraising|campaign3|noaudiencetype|district|ak
<击> 原始答案:
使用点/句点来连接,而不是逗号。
echo $subline."|".$emailtype."|".$campaign."|".$audiencetype."|".$geo."|".$statename;
另外,您的问题代码缺少结束</form>
标记。
击>