Jump to content

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


ask9

Recommended Posts

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

 

Link to comment
Share on other sites

$this->db->update() does not return the query string. It is returning a 1 (one) that either (I don't know which) represents a TRUE value (that the query executed without error) or represents the number of rows that were affected by the query.

 

You are taking that 1 (one) value and putting it into a mysql_query() statement. That is not how you use frameworks. You use the framework methods to execute the query. You should not have any mysql_query/mysql_error statements in your code.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.