错误 MYSQL:致命错误:未捕获 [42S22] - SQLSTATE[42S22]:未找到列:1054 未知列 'id'

发布于 2025-01-09 07:08:28 字数 6787 浏览 3 评论 0原文

我的 CRUD Web 应用程序有问题。

我想从表单中保存值以将它们存储在带有外键的表中。

我的错误:致命错误:未捕获[42S22] - SQLSTATE[42S22]:未找到列:1054 未知列“id”

我想从表单中将输入值保存到名为 Adherents 的表中。 Adherents 表具有以下树状结构:

NameType
id_adherentINT PK AI Unsigned
nom_adherentVARCHAR(45)
prenom_adherentVARCHAR(45)
date_adherentDATE
id_emailINT FK
id_numeroINT FK
id_adresseINT FK
id_cotitationINT FK

这是我的代码 =>

在 MembreController.php 中的

public function showAll(Response $response){
    $adherents = R::getAll("SELECT * FROM adherents");
    return $this->render(
        $response, 
        "membres/membres.twig", [
        "adherentsList" => $adherents]
    );
}
    

public function membresform(Response $response){
    return $this->render(
        $response, 
        "membres/form.twig"
    );
}

public function processForm(Response $response, 
ServerRequestInterface $request){
    $data = $request->getParsedBody();
    var_dump($data);

    $email = R::dispense("emails");
    $email->import($data["emails"]);
    R::store($email);

    $contact = R::dispense("numero_telephones");
    $contact->import($data["numero_telephones"]);
    R::store($contact);

    $adresses = R::dispense("adresses");
    $adresses->import($data["adresses"]);
    R::store($adresses);

    if(empty($data["emails"]["id_email"])){
        $membres = R::dispense("adherents");
    } else {
        $membres = R::load("adherents", $data["emails"]["id_email"]);
    }


    if(empty($data["contact"]["id_numero_telephone"])){
        $membres = R::dispense("adherents");
    } else {
        $membres = R::load("adherents", $data["contact"]["id_numero_telephone"]);
    }


    if(empty($data["adresses"]["id_adresse"])){
        $membres = R::dispense("adherents");
    } else {
        $membres = R::load("adherents", $data["adresses"]["id_adresse"]);
    }



    $membres->import($data["emails"]);
    $membres->emails = $email;

    $membres->import($data["numero_telephones"]);
    $membres->numero_telephones = $contact;

    $membres->import($data["adresses"]);
    $membres->adresses = $adresses;
    R::store($membres);

    return $response->withStatus(302)
                    ->withHeader("location", "/membres");

}

form.twig

{% extends "./base-connected.twig" %}


{% block css %}
 {{ parent() }}
{% endblock %}

{% block content %}
    <form method="post" action="">
        <input type="text" name="adherents[id_adherent]" value="{{membres.id_adherent}}">
        <input type="text" name="emails[id_email]" value="{{membres.email.id_email}}">
        <input type="text" name="contact[id_numero]" value="{{membres.contact.id_numero_telephone}}">
        <input type="text" name="adresses[id_adresse]" value="{{membres.adresses.id_adresse}}">


        <fieldset>
            <legend>Civilité</legend>
        <div class="mb-3 ml-3">
            <label class="form-label">Prénom</label>
            <input class="form-control" type="text" name="adherents[nom]"
            value="{{membres.nom_adherent}}">
        </div>
        <div class="mb-3 ml-3">
            <label class="form-label">Nom</label>
            <input class="form-control" type="text" name="adherents[prenom]"
            value="{{membres.prenom_adherent}}">
        </div>
        <div class="mb-3 ml-3">
            <label class="form-label">Date de Naissance</label>
            <input class="form-control" type="date" name="adherents[date]"
            value="{{membres.date_adherent}}">
        </div>
        </fieldset>

        <fieldset>
            <legend>Contact</legend>
            <div class="mb-3">
                <label class="form-label">Adresse email</label>
                <input class="form-control" type="email" name="emails[email]"
                value="{{membres.emails.email}}">
            </div>
            <div class="mb-3">
                <label class="form-label">Numero de telephone</label>
                <input class="form-control" type="tel" name="contact[numero]"
                value="{{membres.contact.numero}}">
            </div>
        </fieldset>


        <fieldset>
            <legend>Adresse</legend>
            <div class="mb-3">
                <label class="form-label">Rue</label>
                <input class="form-control" type="text" name="adresses[adresse]"
                value="{{membres.adresses.adresse}}">
            </div>
            <div class="mb-3">
                <label class="form-label">Code postal</label>
                <input class="form-control" type="text" name="adresses[code_postale]"
                value="{{membres.adresses.code_postale}}">
            </div>
            <div class="mb-3">
                <label class="form-label">Ville</label>
                <input class="form-control" type="text" name="adresses[ville]"
                value="{{membres.adresses.ville}}">
            </div>
        </fieldset>

        <div class="mb-3">
            <button type="submit" class="btn btn-primary w-100">
                Valider
            </button>
        </div>

    </form>

{% endblock %}

和 var_dump($_POST) 的结果:

array (size=4)
  'adherents' => 
    array (size=4)
      'id' => string '' (length=0)
      'nom' => string 'test' (length=4)
      'prenom' => string 'test' (length=4)
      'date' => string '2022-02-23' (length=10)
  'emails' => 
    array (size=2)
      'id' => string '' (length=0)
      'email' => string '[email protected]' (length=14)
  'contact' => 
    array (size=2)
      'id' => string '' (length=0)
      'numero' => string '0615141216' (length=10)
  'adresses' => 
    array (size=4)
      'id' => string '' (length=0)
      'adresse' => string '13 rue du test' (length=14)
      'code_postale' => string '84520' (length=5)
      'ville' => string 'Hambourg' (length=8)```

i've a problem with my CRUD web application.

I want from a form save the values ​​to store them in a table with foreign keys.

My error : Fatal error: Uncaught [42S22] - SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id'

I want to from a form save the value of input into my table called Adherents. The Adherents table have this arborescence :

NameType
id_adherentINT PK AI Unsigned
nom_adherentVARCHAR(45)
prenom_adherentVARCHAR(45)
date_adherentDATE
id_emailINT FK
id_numeroINT FK
id_adresseINT FK
id_cotisationINT FK

This is my code =>

In the MembreController.php

public function showAll(Response $response){
    $adherents = R::getAll("SELECT * FROM adherents");
    return $this->render(
        $response, 
        "membres/membres.twig", [
        "adherentsList" => $adherents]
    );
}
    

public function membresform(Response $response){
    return $this->render(
        $response, 
        "membres/form.twig"
    );
}

public function processForm(Response $response, 
ServerRequestInterface $request){
    $data = $request->getParsedBody();
    var_dump($data);

    $email = R::dispense("emails");
    $email->import($data["emails"]);
    R::store($email);

    $contact = R::dispense("numero_telephones");
    $contact->import($data["numero_telephones"]);
    R::store($contact);

    $adresses = R::dispense("adresses");
    $adresses->import($data["adresses"]);
    R::store($adresses);

    if(empty($data["emails"]["id_email"])){
        $membres = R::dispense("adherents");
    } else {
        $membres = R::load("adherents", $data["emails"]["id_email"]);
    }


    if(empty($data["contact"]["id_numero_telephone"])){
        $membres = R::dispense("adherents");
    } else {
        $membres = R::load("adherents", $data["contact"]["id_numero_telephone"]);
    }


    if(empty($data["adresses"]["id_adresse"])){
        $membres = R::dispense("adherents");
    } else {
        $membres = R::load("adherents", $data["adresses"]["id_adresse"]);
    }



    $membres->import($data["emails"]);
    $membres->emails = $email;

    $membres->import($data["numero_telephones"]);
    $membres->numero_telephones = $contact;

    $membres->import($data["adresses"]);
    $membres->adresses = $adresses;
    R::store($membres);

    return $response->withStatus(302)
                    ->withHeader("location", "/membres");

}

Dans le form.twig

{% extends "./base-connected.twig" %}


{% block css %}
 {{ parent() }}
{% endblock %}

{% block content %}
    <form method="post" action="">
        <input type="text" name="adherents[id_adherent]" value="{{membres.id_adherent}}">
        <input type="text" name="emails[id_email]" value="{{membres.email.id_email}}">
        <input type="text" name="contact[id_numero]" value="{{membres.contact.id_numero_telephone}}">
        <input type="text" name="adresses[id_adresse]" value="{{membres.adresses.id_adresse}}">


        <fieldset>
            <legend>Civilité</legend>
        <div class="mb-3 ml-3">
            <label class="form-label">Prénom</label>
            <input class="form-control" type="text" name="adherents[nom]"
            value="{{membres.nom_adherent}}">
        </div>
        <div class="mb-3 ml-3">
            <label class="form-label">Nom</label>
            <input class="form-control" type="text" name="adherents[prenom]"
            value="{{membres.prenom_adherent}}">
        </div>
        <div class="mb-3 ml-3">
            <label class="form-label">Date de Naissance</label>
            <input class="form-control" type="date" name="adherents[date]"
            value="{{membres.date_adherent}}">
        </div>
        </fieldset>

        <fieldset>
            <legend>Contact</legend>
            <div class="mb-3">
                <label class="form-label">Adresse email</label>
                <input class="form-control" type="email" name="emails[email]"
                value="{{membres.emails.email}}">
            </div>
            <div class="mb-3">
                <label class="form-label">Numero de telephone</label>
                <input class="form-control" type="tel" name="contact[numero]"
                value="{{membres.contact.numero}}">
            </div>
        </fieldset>


        <fieldset>
            <legend>Adresse</legend>
            <div class="mb-3">
                <label class="form-label">Rue</label>
                <input class="form-control" type="text" name="adresses[adresse]"
                value="{{membres.adresses.adresse}}">
            </div>
            <div class="mb-3">
                <label class="form-label">Code postal</label>
                <input class="form-control" type="text" name="adresses[code_postale]"
                value="{{membres.adresses.code_postale}}">
            </div>
            <div class="mb-3">
                <label class="form-label">Ville</label>
                <input class="form-control" type="text" name="adresses[ville]"
                value="{{membres.adresses.ville}}">
            </div>
        </fieldset>

        <div class="mb-3">
            <button type="submit" class="btn btn-primary w-100">
                Valider
            </button>
        </div>

    </form>

{% endblock %}

And the result of var_dump($_POST) :

array (size=4)
  'adherents' => 
    array (size=4)
      'id' => string '' (length=0)
      'nom' => string 'test' (length=4)
      'prenom' => string 'test' (length=4)
      'date' => string '2022-02-23' (length=10)
  'emails' => 
    array (size=2)
      'id' => string '' (length=0)
      'email' => string '[email protected]' (length=14)
  'contact' => 
    array (size=2)
      'id' => string '' (length=0)
      'numero' => string '0615141216' (length=10)
  'adresses' => 
    array (size=4)
      'id' => string '' (length=0)
      'adresse' => string '13 rue du test' (length=14)
      'code_postale' => string '84520' (length=5)
      'ville' => string 'Hambourg' (length=8)```

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文