dss524049 2014-11-26 04:06
浏览 54
已采纳

输入没有传递给PHP脚本

I have a html form below:

    <section id="main" style="float: right;  text-align: left;  width: 83%;">   
        <article>
            <form>
                <p>Name:   <div><input id="name" type=text/></p></div><br \>
                <p>Phone:   <div><input id="phone" type=text/></p></div><br \>
                <p>Address:   <div><input id="address" type=text/></p></div><br \>
                <p>Username:   <div><input id="username" type=text/></p></div><br \>
                <p>Password:   <div><input id="password" type="password"/></p></div><br \>
                <p>Email:   <div><input id="email" type="text"/></p></div>
                <div><input id="submitDB" type="submit" value="Register"/></div>
            </form>
            <script type="text/javascript">
                      $('#submitDB').on('click', function() {
                          event.preventDefault();

                          $.ajax({
                               url: "registerDB.php",
                               data: { name: $('#name').val(), phone: $('#phone').val(), address: $('#address').val(), username: $('#username').val(), password: $('#password').val(), email: $('#email').val()},
                               type: "POST"
                          }).done(function(data) {
                              if(data === "true"){
                                  alert(data);
                              }
                              else
                              {
                                  alert(data);
                              }
                          });

                      });
           </script>
        </article>
    </section>

This form should submit the inputs and call a "registerDB.php" file which contains

    <?php
        require_once("config.php");
        require_once("MysqliDb.php");

        $DB = new MysqliDb($DBCREDS['HOSTNAME'], $DBCREDS['USERNAME'], $DBCREDS['PASSWORD'], $DBCREDS['DATABASE']);

        $name = $_POST["name"];
        $phone = $_POST['phone'];
        $address = $_POST['address'];
        $username = $_POST['username'];
        $password = $_POST['password'];
        $email = $_POST['email'];



        $data = Array ("name" => $name,
                       "phone" => $phone,
                       "address" => $address,
                       "email" => $email,
                    );

        var_dump($data);
       if($DB->insert('member', $data))
        {
                $user = Array ( 
                        "username" => $username,
                        "password" => $password,
                        );

                        var_dump($user);
                        die();
            if($DB->insert('member_login', $user))
            {
                echo "You are now registered!";
            }
        }   
        else
        {
            echo "Please Fill All Data And Resubmit";
        }





    ?>

However the username and password variables are not passing through. Is there something I am missing here? This does not have to be super "secure" I am working on a project for my System Analysis class and basically am working on making a website for a presentation.

  • 写回答

4条回答 默认 最新

  • dsbm49845 2014-11-26 04:09
    关注

    You need to add the name attribute to your inputs. Such as:

    <form id="myForm">
        <p>Name:   <div><input id="name" name="name" type=text/></p></div><br \>
        <p>Phone:   <div><input id="phone" name="phone" type=text/></p></div><br \>
        <p>Address:   <div><input id="address" name="address" type=text/></p></div><br \>
        <p>Username:   <div><input id="username" name="username" type=text/></p></div><br \>
        <p>Password:   <div><input id="password" name="password" type="password"/></p></div><br \>
        <p>Email:   <div><input id="email" name="email" type="text"/></p></div>
        <div><input id="submitDB" type="submit" value="Register"/></div>
    </form>
    

    And use the following to submit the form #myForm with jquery. (make 'myForm' as the id of your form)

    $("#myForm").ajaxForm({url: 'registerDB.php', type: 'post'})
    

    TIP: use ajaxForm so as not to reinvent the wheel when creating ajax forms.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)