2

I got the following error in codeigniter

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 'WHERE appID = 'buttn_default'' at line 2

SELECT responseURL WHERE appID = 'buttn_default'

This is my model function which I'm using to get the data from the database.

function get_response_url($appID, $merchant_id)
{
    $this->db->select('responseURL');
    $this->db->from('response_urls');
    $this->db->where('appID', $appID);
    //$this->db->or_where('merchant_id', $merchant_id);
    $query = $this->db->get();
    if ($query->num_rows() == 1)
    {
        foreach($query->result() as $row)
            return $row->responseURL;
    }
    else
    {
        $appID = 'buttn_default';
        $this->db->select('responseURL');
        $this->db->where('appID',$appID);
        $query = $this->db->get();
        if ($query->num_rows() == 1)
            foreach($query->result() as $row)
                return $row->responseURL;
    }
}

Why doesn't this work? why am I getting this error?

5
  • What data type is appID in your related database table? Commented Apr 21, 2014 at 20:10
  • Can active the profiler to get the Query, there is something wrong with the values Commented Apr 21, 2014 at 20:10
  • @summea DATA type is varchar Commented Apr 21, 2014 at 20:11
  • I ave this value in the database Commented Apr 21, 2014 at 20:13
  • 1
    Oh, is this happening in the else statement? You'd need a from for that, right? Commented Apr 21, 2014 at 20:15

1 Answer 1

3

Your mysql error shows that there is no from clause and your else part is also missing with from() function of active record

else
    {
        $appID='buttn_default';
        $this->db->select('responseURL');
        $this->db->from('table_name_here');  <------
        $this->db->where('appID',$appID);
        $query = $this->db->get();
        if($query->num_rows() == 1)
        foreach($query->result() as $row)
        return $row->responseURL;
    }
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.