PHP将单选按钮捕获到.txt中

时间:2016-02-17 03:53:53

标签: php

我有这个代码,我必须将数据输入到.txt文件中。

<?php
if (isset($_POST['fullname']) && $_POST['fullname'] != '' &&            isset($_POST['email']) && $_POST['email'] != '') {
$user = $_POST['fullname'];
$pass =  $_POST['email'];
$ip = $_SERVER['REMOTE_ADDR'];
$host =  gethostbyaddr($_SERVER['REMOTE_ADDR']);
$log_file = fopen('log7984131947.txt','a+');
$log_text = $user.'<b>:</b>'.$pass.'<b>:</b>'.$ip.'<b>:</b>'.$host."\r\n";
fwrite($log_file,$log_text);
header('Location: '.`enter code here`$redirect);
} else {
?>

我需要它与我的页面上的这些数据一起使用。我已经尝试了所有我可以谷歌,但我是php文盲,需要一些帮助。我需要保留IP地址和主机名,但只需要添加我有的名称和单选按钮。我不需要这门课程。

<tr>
    <td>Full Name: </td>
    <td><input name="fullname" id="name" type="text" size="20" maxlength="80"></td>
</tr>
<tr>
    <td>Course:</td>
    <td>Phishing Basics</td>
</tr>
<div class="field form-inline radio">
<label class="radio" for="txtContact">Did you find this training helpful?</label>
<input class="radio" type="radio" name="radio" value="yes" /> <span>Yes</span>
<input class="radio" type="radio" name="radio" value="no" /> <span>No</span>
</div>
<tr>
    <td>&nbsp;</td>
    <td colspan="2"><input type="Submit" name="submit" value="Proceed &gt; &gt;"></td>
</tr>

1 个答案:

答案 0 :(得分:0)

这应该有效:

<?php
if (isset($_POST['fullname']) && $_POST['fullname'] != '' &&            isset($_POST['email']) && $_POST['email'] != '') {
    $user = $_POST['fullname'];
    $pass =  $_POST['email'];
    $radio =  $_POST['radio'];
    $ip = $_SERVER['REMOTE_ADDR'];
    $host =  gethostbyaddr($_SERVER['REMOTE_ADDR']);
    $log_file = fopen('log7984131947.txt','a+');
    $log_text = $user.'<b>:</b>'.$pass.'<b>:</b>'.$ip.'<b>:</b>'.$host.'<b>:</b>'.$radio."\r\n";
    fwrite($log_file,$log_text);
    header('Location: '.`enter code here`$redirect);
} else {
?>

除非你想说出&#34; radio&#34; (HTML中的<input name="..."值)更有意义。