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

146 Views Asked by At

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 :

Name Type
id_adherent INT PK AI Unsigned
nom_adherent VARCHAR(45)
prenom_adherent VARCHAR(45)
date_adherent DATE
id_email INT FK
id_numero INT FK
id_adresse INT FK
id_cotisation INT 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)```
0

There are 0 best solutions below