douqian9729 2013-09-12 01:19
浏览 30
已采纳

当我在php中发布时传递空值

I am having trouble figuring out why no matter what the address and city fields are always null for me. I input any basic data, post it and get on the other side and it says it's null. Anything obvious I'm doing wrong? Thanks in advance.

This is how I get the values passed via post:

$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$phone = $_POST['phone'];
$address_one = $_POST['address_one'];
$address_two = $_POST['address_two'];
$city = $_POST['city'];
$age = $_POST['age'];

Form I use to collect the data:

 <form id='login' action='createreg.php' method='post' accept-charset='UTF-8'>
                <h3>Create an Account</h3>
                <table id='registertb'>

                    <tr>
                        <td>Username:</td>
                        <td>
                        <input type='text' name='username' id='username' class='loginfield' maxlength="50" />
                        </td>
                    </tr>
                    <tr>
                        <td>Password:</td>
                        <td>
                        <input type='password' name='password' id='password' class='loginfield' maxlength="50" />
                        </td>
                    </tr>
                    <tr>
                        <td>Email:</td>
                        <td>
                        <input type='text' name='email' id='email' class='loginfield' maxlength="50" />
                        </td>
                    </tr>
                    <tr>
                        <td>First Name:</td>
                        <td>
                        <input type='text' name='fname' id='fname' class='loginfield' maxlength="50" />
                        </td>
                    </tr>
                    <tr>
                        <td>Last Name:</td>
                        <td>
                        <input type='text' name='lname' id='lname' class='loginfield' maxlength="50" />
                        </td>
                    </tr>
                    <tr>
                        <td>Phone:</td>
                        <td>
                        <input type='text' name='phone' id='phone' class='loginfield' maxlength="50" />
                        </td>
                    </tr>
                    <tr>
                        <td>Address Line 1:</td>
                        <td>
                        <input type='text' name='address1' id='address1' class='loginfield' maxlength="50" />
                        </td>
                    </tr>
                    <tr>
                        <td>Address Line 2:</td>
                        <td>
                        <input type='text' name='address2' id='address2' class='loginfield' maxlength="50" />
                        </td>
                    </tr>
                    <tr>
                        <td>City:</td>
                        <td>
                        <input type='text' name='address2' id='address2' class='loginfield' maxlength="50" />
                        </td>
                    </tr>
                    <tr>
                        <td>Age:</td>
                        <td>
                        <input type='text' name='age' id='age' class='loginfield' maxlength="50" />
                        </td>
                    </tr>
                    <tr>
                        <td><a href='index.html'>Login</a></td>
                        <td align='right'>
                        <input type='submit' id='subbutton' value='Create' class='buttons' />
                        </td>
                    </tr>
                </table>
  • 写回答

1条回答 默认 最新

  • doubi1910 2013-09-12 01:23
    关注

    You've named your inputs incorrectly. In your PHP, you use these to set the variables:

    $address_one = $_POST['address_one'];
    $address_two = $_POST['address_two'];
    $city = $_POST['city'];
    

    But the HTML references the address fields by number, and the city input is actually a duplicate of address2. You need to set the input name attributes to match what you're using inside the $_POST variables.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题