duandaotuo5542 2014-03-11 22:46
浏览 55
已采纳

尝试使用PHP创建HTML表单将内容发送到CSV文件

I currently have this code exactly:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Reg</title>
    </head>

    <body>
        <form id="form1" name="form1" method="post" action="post.php">
            <table width="597" class="formatTblClass">
                <tr>
                    <th colspan="4"></th>
                </tr>
                <tr>
                    <td width="99"><span>First Name</span></td>
                    <td width="217"><input class="" type="text" name="fn" id="fn" /></td>
                    <td width="99"><span>Last Name</span></td>
                    <td width="211"><input class="" name="ln" type="text" id="ln" /></td>
                </tr>

                <tr>
                    <td colspan="4">Check groups that you would like to receive updates about</td>
                </tr>
                <tr>
                    <td><input name="1" type="checkbox" id="1" value="a" /></td>
                    <td>A</td>
                    <td><input name="4" type="checkbox" id="4" value="b" /></td>
                    <td>B</td>
                </tr>
                <tr>
                    <td><input name="2" type="checkbox" id="2" value="c" /></td>
                    <td>C</td>
                    <td><input name="5" type="checkbox" id="5" value="d" /></td>
                    <td>D</td>
                </tr>
                <tr>
                    <td><input name="3" type="checkbox" id="3" value="e" /></td>
                    <td>E</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td colspan="4">
                        <div align="center">
                            <input type="submit" name="Submit" id="Submit" value="Submit" />
                            <input type="reset" name="Reset" id="button" value="Reset" />
                        </div>
                    </td>
                </tr>
        </table>
    </form>
</body>
</html>

<?php
    $fn = $_POST['fn'];
    $ln = $_POST['ln'];
    $1 = (isset($_POST[1])) ? $_POST[1] : No;
    $2 = (isset($_POST[2])) ? $_POST[2] : No;
    $3 = (isset($_POST['3'])) ? $_POST['3'] : 'No';
    $4 = (isset($_POST['4'])) ? $_POST['4'] : 'No';
    $5 = (isset($_POST['5'])) ? $_POST['5'] : 'No';

    //validate

    if(empty($fn) || empty($ln) || empty($phone)){//show the form
        $message = 'Fill in areas in red!';
        $aClass = 'errorClass';
    }

    //this is where the creating of the csv takes place
    $cvsData = $fn . "," . $ln . "," . $1 ."
";

    $fp = fopen("pwrtest.csv","a"); // $fp is now the file pointer to file $filename

    if($fp){
        fwrite($fp,$cvsData); // Write information to the file
        fclose($fp); // Close the file
    }

?>

On the PHP page I get an error:

Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in /home/aaaaaaa/public_html/aaaaaaaa.com/formtest/post.php on line 5

--

I am pretty new to code so I would appreciate any help greatly.

Thanks for your time.

Best Regards, V. Kije

  • 写回答

1条回答 默认 最新

  • duanjumie8753 2014-03-11 22:55
    关注

    PHP variable names MUST start with an alphabetical character. $1, $2, etc... are NOT valid, except when used in preg_*() expressions.

    $1 = (isset($_POST[1])) ? $_POST[1] : No;
     ^--- illegal variable name
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)