$ _POST数据未传递到数据库

时间:2014-07-24 14:28:56

标签: php laravel-4

y'所有,我正在制作一个简单的注册/注册表单,然后将其提交到我的(localhost)数据库。我遇到的主要问题是我无法将数据实际传递到我的数据库。我正在使用Laravel 4来处理后端,但我对它很新,所以我确定我犯了一个明显的错误,但我似乎无法看到它。

这是我使用Twitter Bootstrap创建的表单。这没有什么不对 action =" / adding_to_table"路线呼叫。

<!DOCTYPE html>
<html>
<head>
    <link class="cssdeck" rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.1/css/bootstrap-responsive.min.css" class="cssdeck">
</head>
<body>
<div class="" id="loginModal">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <!--<h3>Have an Account?</h3>-->
    </div>
    <div class="modal-body">
        <div class="well">
            <div id="myTabContent" class="tab-content">
                <div class="tab-pane active in" id="login">
                    <form method="" action='/adding_to_table' class="form-horizontal">
                        <fieldset>
                            <div id="legend">
                                <legend class="">Create Your Account</legend>
                            </div>
                            <div class="control-group">
                                <!-- Username -->
                                <label class="control-label"  for="firstname">First Name</label>
                                <div class="controls">
                                    <input type="text" id="first_name" name="firstname" placeholder="" class="input-xlarge">
                                </div>
                            </div>

                            <div class="control-group">
                                <!-- Username -->
                                <label class="control-label"  for="lastname">Last Name</label>
                                <div class="controls">
                                    <input type="text" id="last_name" name="lastname" placeholder="" class="input-xlarge">
                                </div>
                            </div>

                            <div class="control-group">
                                <!-- Username -->
                                <label class="control-label"  for="email">E-mail</label>
                                <div class="controls">
                                    <input type="text" id="e_mail" name="email" placeholder="" class="input-xlarge">
                                </div>
                            </div>

                            <div class="control-group">
                                <!-- Username -->
                                <label class="control-label"  for="username">Username</label>
                                <div class="controls">
                                    <input type="text" id="username" name="username" placeholder="" class="input-xlarge">
                                </div>
                            </div>


                            <div class="control-group">
                                <!-- Password-->
                                <label class="control-label" for="password">Password</label>
                                <div class="controls">
                                    <input type="password" id="password" name="password" placeholder="" class="input-xlarge">
                                </div>
                            </div>

                            <div class="control-group">
                                <!-- Button -->
                                <div class="controls">
                                    <button class="btn btn-primary">Submit</button>
                                </div>
                            </div>
                        </fieldset>
                    </form>                
                </div>
            </div>
        </div>
    </div>

<script class="cssdeck" src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script class="cssdeck" src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
</body>
<html>

现在,这是应该将数据放入数据库的文件:

DB::table('user_info')->insert(
        array("First_name" => Input::get('first_name'),
              "Last_name" => Input::get("last_name"),
              "E-mail" => Input::get("e_mail"),
              "Username" => Input::get("username"),
              "Password" => Input::get("password")
            )
        );

    echo "Successfully entered user information into data table";

每当我填写表格并点击提交时,我就会得到#34;哎呀,看起来出了问题&#34; Laravel的错误,我不太清楚为什么。我们非常感谢所有人给予的任何帮助!

1 个答案:

答案 0 :(得分:1)

您定位的是表单元素的ID而不是名称。尝试使用name属性:

DB::table('user_info')->insert(
        array("First_name" => Input::get('firstname'),
              "Last_name" => Input::get("lastname"),
              "E-mail" => Input::get("email"),
              "Username" => Input::get("username"),
              "Password" => Input::get("password")
            )
        );

如果您使用method="POST",请尝试:

DB::table('user_info')->insert(
        array("First_name" => Input::post('firstname'),
              "Last_name" => Input::post("lastname"),
              "E-mail" => Input::post("email"),
              "Username" => Input::post("username"),
              "Password" => Input::post("password")
            )
        );