首页 > 解决方案 > 如何使用下面的代码使我的更新查询工作

问题描述

我正在使用 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>
                  <div class="form-group">

                    <div class="col-xs-12">
                      <label for="email">
                        <h4>Email</h4></label>
                        <input type="email" class="form-control" name="email" id="email" placeholder="<?= $user->email; ?>" title="enter your email.">
                      </div>
                    </div>

                    <div class="form-group">
                      <div class="col-xs-12">
                        <br>
                        <button class="btn btn-lg btn-success" type="submit" name="submit"><i class="glyphicon glyphicon-ok-sign"></i> Sla op</button>
                        <button class="btn btn-lg" type="reset" name="resetww"><i class="glyphicon glyphicon-repeat"></i> Verander wachtwoord</button>
                      </div>
                    </div>
                  </form>

                  <?php

                  if (isset($_POST['submit'])) {

                    $voornaam = $_POST['voornaam'];
                    $achternaam = $_POST['achternaam'];
                    $gebruikersnaam = $_POST['gebruikersnaam'];
                    $telefoonnummer = $_POST['telefoonnummer'];
                    $email = $_POST['email'];
                    App\User::where('klant_id', 1)->update(['gebruikersnaam' => $gebruikersnaam, 'voornaam' => $voornaam, 'achternaam' => $achternaam, 'email' => $email ,'telefoonnummer' => $telefoonnummer]);
                  }

                   ?>

我希望更新我的数据库

标签: phpsqllaravelformsinsert

解决方案


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

方法="发布"


推荐阅读