Welcome Guest, Not a member yet? Register   Sign In
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right synta
#1

[eluser]solid9[/eluser]
Hi guys

Can you help 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:
Code:
<?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:
Code:
&lt;?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);
  
  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




Theme © iAndrew 2016 - Forum software by © MyBB