如何使用下面的代码使我的更新查询工作

我正在使用 php 和一些 Laravel 设置更新配置文件页面。我有一个 if 检查来检查表单是否已提交,并且我有一个更新查询。


更新查询只能在 if 语句之外工作,我不知道为什么。如果我放在 if 语句里面,它不会做任何事情。我已经检查过所有名称是否与我的 sql 数据库中的名称相同,并且它们都是正确的。


    <form class="form" id="registrationForm">

          <div class="form-group">


            <div class="col-xs-6">

              <label for="first_name">

                <h4>Voornaam</h4></label>

                <input type="text" class="form-control" name="voornaam" id="first_name" placeholder="<?= $user->voornaam; ?>" title="enter your first name if any.">

              </div>

            </div>

            <div class="form-group">


              <div class="col-xs-6">

                <label for="last_name">

                  <h4>Achternaam</h4></label>

                  <input type="text" class="form-control" name="achternaam" id="last_name" placeholder="<?= $user->achternaam; ?>" title="enter your last name if any.">

                </div>

              </div>


              <div class="form-group">


                <div class="col-xs-6">

                  <label for="phone">

                    <h4>Gebruikersnaam</h4></label>

                    <input type="text" class="form-control" name="gebruikersnaam" id="username" placeholder="<?= $user->gebruikersnaam; ?>" title="enter your phone number if any.">

                  </div>

                </div>


                <div class="form-group">

                  <div class="col-xs-6">

                    <label for="mobile">

                      <h4>Telefoon nummer</h4></label>

                      <input type="text" class="form-control" name="telefoonnummer" id="mobile" placeholder="<?= $user->telefoonnummer; ?>" title="enter your mobile number if any.">

                    </div>

                  </div>

我想更新我的数据库


绝地无双
浏览 109回答 2
2回答

慕少森

将标签放入您的表单中,PHP 正在尝试查找 de POST 但您没有发送它。方法=“POST”

扬帆大鱼

首先提到下面的表单方法并使用csrf令牌@csrf为什么你不能使用控制器来完成这项工作首先使用控制器,然后制作一个更新信息的方法public function update_user(Request $request){&nbsp; &nbsp; &nbsp; if ($request->isMethod('post')) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $data = $request->all();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; User = new User();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $voornaam = $_POST['voornaam'];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $achternaam = $data['achternaam'];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $gebruikersnaam = $data['gebruikersnaam'];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $telefoonnummer = $data['telefoonnummer'];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $email = $data['email'];enter code here&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP