我有一个HTML表单,并使用get方法如何变量匹配我的HTML表格到PHP
我想输入的数据,如果用户选择鞋期权价值shoes_sales.txt,并输入所有休息到clothes_sales.txt。不幸的是,这些数据并未出现在我的.txt
中。
这是HTML表单:
<li class="form-line" id="id_16">
<label class="form-label-left" id="label_16" for="input_16"> Select choice </label>
<div id="cid_16" class="form-input">
<select class="form-dropdown" style="width:150px" id="input_16" name="q16_selectFrom16">
<option value="Shoes"> Shoes </option>
<option value="Clothes"> Clothes </option>
</select>
</div>
</li>
这是PHP尝试检索表单值:
<?php
header("Location: thankforsumbitting.html");
if ($_GET['variable1'] == "shoes") {
$handle = fopen("shoes_sales.txt", "a");
}
else {
$handle = fopen("clothes_sales.txt", "a");
}
foreach($_GET as $variable => $value) {
fwrite($handle, $variable."=".$value."\r\n");
}
fclose($handle);
exit;
?>
把'header'重定向末;它可能会在用户开始写文本文件之前重定向用户。 – andrewsi
我认为这个'header(“Location:thankforsumbitting.html”);'即使在脚本尝试写入文件之前也会立即重定向。尝试拿出或使用'回声“谢谢你”;'。虽然这没有经过测试,我现在没有时间进行测试。尝试把它放在'fclose($ handle);'而不是,但是这可能会导致'headers already sent'错误消息。 –
@andrewsi你在11秒内击败了我! –