The right syntax to use near ‘1’ at line 1

Hi guys,

Can you hel p me with this,

Error:
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 ‘1’ at line 1

Controller:


<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Prod_c extends CI_Controller {
	public function __construct() {
		parent::__construct();
	
		$this->load->helper('form');  
		$this->load->helper('html');      
		$this->load->model('prod_m');
	}
	
	//fetch all product records
	//display all records to prod_show.php
	//http://herpescureresearch.org/researchers/prod_c/prod_show/
	function prod_show() {	
		$data['rows'] = $this->prod_m->getAll();
		
		$this->load->view('prod_show', $data);
	}
	
	function prod_edit() {
		//capture url
		$prod_name = $this->uri->segment(3, 0);
		
		$query = $this->prod_m->getProduct($prod_name);
		
		//echo '<pre>';
		//print_r($query);
		//echo '</pre>';
		
	    $data['prod_name'] = $query['prod_name'];
	    $data['org'] = $query['org'];
		$data['phase'] = $query['phase'];
		$data['type'] = $query['type'];		
		$data['description'] = $query['description'];
		$data['main_url'] = $query['main_url'];
		$data['donation_url'] = $query['donation_url'];		
		
		$this->load->view('prod_edit_form',$data);   
	}
	
	function prod_edit_update() {
		//capture all post data
		if (isset($_POST['butedit'])) { 
		    $data['prod_name'] = $_POST['prod_name'];
		    $data['org'] = $_POST['org'];
			$data['phase'] = $_POST['phase'];
			$data['type'] = $_POST['type'];		
			$data['description'] = $_POST['description'];
			$data['main_url'] = $_POST['main_url'];
			$data['donation_url'] = $_POST['donation_url'];		
			
			//update database
			$data['message'] = $this->prod_m->updateProduct($data);		

			//redirect to success page
			$this->load->view('prod_success', $data);						
		} 		
	}

	function prod_delete() {
		$prod_name = $this->uri->segment(3, 0);
			
	}

	function prod_success() {
	
	}
	
}
/* End of file prod_c.php */
/* Location: ./application/controllers/prod_c.php */

Model:


<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Prod_m extends CI_Model {
	
	function getAll() {
		$this->db->select('prod_name');
		$this->db->from('products');
		//$this->db->where('id', 1);
		
		$q = $this->db->get();
		
		if($q->num_rows() > 0) {
			foreach ($q->result() as $row) {
				$data[] = $row;
			}
			return $data;
		}
	}		
	
	function getProduct($prod_name){
		$this->db->select('prod_name, org, phase, type, description, main_url, donation_url');
		$this->db->from('products');
		$this->db->where('prod_name', $prod_name);
		$query = $this->db->get();

		if($query->num_rows() > 0) {
			return $query->row_array();
		}
	}
	
	function updateProduct($data) {
		$prod_name = $data['prod_name'];
		$this->db->where('prod_name', $prod_name);
		$query = $this->db->update('products', $data); 
		
		echo '<pre>';
		print_r($data);
		echo '<pre>';
		
		if (mysql_query($query))
		{
			$message = 'Record successfully updated!';
		}
		else
		{
			$message = mysql_error();
		}
		return $message;
	}
	
}
/* End of file prod_m.php */
/* Location: ./application/model/prod_m.php */

The error occur when the method in the model “productUpdate” is called.
Why is this exactly?

Thanks in advanced

Can you please post the query as built by your code?

@SpacePhoenix thanks for the reply.

This is CodeIgniter using Active Records.

You will have better responses on the ci forum or php, very few here probably understand that gibberish query builder. This has less do with MySQL and more to do with incorrectly using the ci ActiveRecord implementation.

Echo out the query and see what it says.