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 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看