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 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 定制ai直播实时换脸软件
  • ¥100 栈回溯相关,模块加载后KiExceptionDispatch无法正常回溯了
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding
  • ¥15 Marscode IDE 如何预览新建的 HTML 文件
  • ¥15 K8S部署二进制集群过程中calico一直报错