0

I am new to php and sql, and I found this free to download web project online about a stock database and I wanted to learn more about php and sql over this project.

My issue is that after I login the web page, the page appearing next shows this:

A Database Error Occurred Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'groups ON groups.id = user_group.group_id WHERE user_group.user_id = '1'' at line 2

SELECT * FROM user_group INNER JOIN groups ON groups.id = user_group.group_id WHERE user_group.user_id = '1'

Filename: models/Model_groups.php

Line Number: 55

the line number 55 in Model_groups.php has this:

$query = $this->db->query($sql, array($user_id));

Hope to get some help, all the best.

The full php of Model_groups.php is:


class Model_groups extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }

    public function getGroupData($groupId = null) 
    {
        if($groupId) {
            $sql = "SELECT * FROM groups WHERE id = ?";
            $query = $this->db->query($sql, array($groupId));
            return $query->row_array();
        }

        $sql = "SELECT * FROM groups WHERE id != ?";
        $query = $this->db->query($sql, array(1));
        return $query->result_array();
    }

    public function create($data = '')
    {
        $create = $this->db->insert('groups', $data);
        return ($create == true) ? true : false;
    }

    public function edit($data, $id)
    {
        $this->db->where('id', $id);
        $update = $this->db->update('groups', $data);
        return ($update == true) ? true : false;    
    }

    public function delete($id)
    {
        $this->db->where('id', $id);
        $delete = $this->db->delete('groups');
        return ($delete == true) ? true : false;
    }

    public function existInUserGroup($id)
    {
        $sql = "SELECT * FROM user_group WHERE group_id = ?";
        $query = $this->db->query($sql, array($id));
        return ($query->num_rows() == 1) ? true : false;
    }

    public function getUserGroupByUserId($user_id) 
    {
        $sql = "SELECT * FROM user_group 
        INNER JOIN groups ON groups.id = user_group.group_id 
        WHERE user_group.user_id = ?";
        $query = $this->db->query($sql, array($user_id));
        return $query->row_array();

    }
}```
Mekiro
  • 7
  • 1

0 Answers0