Table No data

  • Question of adding data to the OBD table. The challenge is next. The user on the dashboard is in the form of the results of his weighting and measurements (kg, fat content, chest volumes, waist, etc.). These data should be recorded in the OBD table. I created a table parametrs. According to the logic I wrote in the code, after I pressed the button to send it on the same page, the form should be processed and post data transmitted. Controller UserWeight accepts the data from the form, transmits to WeightModel, where the function addParametrs adds values to the respective boxes of table parametrs. However, someone in this chain cannot understand this logic and the data are not available in the table. I ran without checking the form, and I was forced to execute the numbers, they still don't get to the table. (grunts) Clarification: 1. The form is processed as the page is updated; 2. Connection to the OBD is provided in a separate file through which other forms successfully interact with other OBD tables. Controller:

        class UserWeight extends Controller {
        public function userWeight() {
            $data = [];
            if(isset($_POST['weight'])) {
                    $user = $this-&gt;model('WeightModel');
                    $user-&gt;setData($_POST['weight'], $_POST['fat'], $_POST['visceral'], $_POST['bone'], $_POST['water'],
                                    $_POST['muscles'], $_POST['physical'], $_POST['metabolism'], $_POST['age'], $_POST['breast'],
                                    $_POST['waist'], $_POST['hips']);

    // $isValid = $user->validForm();
    // if($isValid == "Верно")
    // else
    // $data['message'] = $isValid;

        $this-&gt;view('user/dashboard', $data);


        require 'DB.php';
        class WeightModel
        private $weight;
        private $fat;
        private $visceral;
        private $bone;
        private $water;
        private $muscles;
        private $physical;
        private $metabolism;
        private $age;
        private $breast;
        private $waist;
        private $hips;
        private $_db = null;
        public function __construct()
            $this-&gt;_db = DB::getInstence();
        public function setData($weight, $fat, $visceral, $bone, $water, $muscles, $physical, $metabolism, $age, $breast,
                                $waist, $hips)
    //            $this-&gt;date = $date;
            $this-&gt;weight = $weight;
            $this-&gt;fat = $fat;
            $this-&gt;visceral = $visceral;
            $this-&gt;bone = $bone;
            $this-&gt;water = $water;
            $this-&gt;muscles = $muscles;
            $this-&gt;physical = $physical;
            $this-&gt;metabolism = $metabolism;
            $this-&gt;age = $age;
            $this-&gt;breast = $breast;
            $this-&gt;waist = $waist;
            $this-&gt;hips = $hips;
        public function addParametrs()
            $sql = 'INSERT INTO parametrs (weight, fat, visceral, bone, water, muscles, physical, metabolism, age, breast, waist, hips) 
                        VALUES(:weight, :fat, :visceral, :bone, :water, :muscles, :physical, :metabolism, :age, :breast, :waist, :hips)';
            $query = $this-&gt;_db-&gt;prepare($sql);
            $query-&gt;execute(['weight' =&gt; $this-&gt;weight, 'fat' =&gt; $this-&gt;fat, 'visceral' =&gt; $this-&gt;visceral, 'bone' =&gt; $this-&gt;bone,
                'water' =&gt; $this-&gt;water, 'muscles' =&gt; $this-&gt;muscles, 'physical' =&gt; $this-&gt;physical, 'metabolism' =&gt; $this-&gt;metabolism,
                'age' =&gt; $this-&gt;age, 'breast' =&gt; $this-&gt;breast, 'waist' =&gt; $this-&gt;waist, 'hips' =&gt; $this-&gt;hips]);

  • I think you misrepresented the parameters.

    $query->execute(['weight' => $this->weight, 'fat' => $this->fat, 'visceral' => $this->visceral, 'bone' => $this->bone,
                'water' => $this->water, 'muscles' => $this->muscles, 'physical' => $this->physical, 'metabolism' => $this->metabolism,
                'age' => $this->age, 'breast' => $this->breast, 'waist' => $this->waist, 'hips' => $this->hips]);

    I think it should be like,

    $query->execute([':weight' => $this->weight, ':fat' => $this->fat, ':visceral' => $this->visceral, ':bone' => $this->bone,
                    ':water' => $this->water, ':muscles' => $this->muscles, ':physical' => $this->physical, ':metabolism' => $this->metabolism,
                    ':age' => $this->age, ':breast' => $this->breast, ':waist' => $this->waist, ':hips' => $this->hips]);

Log in to reply

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2