หน้า 1 จากทั้งหมด 1

insert ข้อมูลเข้าฐานข้อมูลไม่ได้ค่ะ

โพสต์แล้ว: 27/04/2016 6:01 pm
โดย M034
ช่วยดูหน่อยค่ะ ไม่รู้ว่าติดตรงไหน ถึงinsert ไม่ได้

โค้ด: เลือกทั้งหมด

public function plant($action) {

		switch ($action) {
			case 'show_all':

				$this->show_data_all();

				$this->template->assign_vars(array(
				    'SHOW_ALL' => true,
				    'A_ACTION' => $this->helper->route('myproject_controller', array('action' => 'add_data'))
				));
				break;

			case 'add_data':

				$data = array(
				    'plant_id' => $this->request->variable('plant_id', ''),
				    'plant_name ' => $this->request->variable('plant_name', '', true),
				    
				);



				$this->insert($data);


				$this->template->assign_vars(array(
				    'SHOW_FORM_ADD' => true,
				));

				break;

			default:
				break;
		}
		return $this->helper->render('plant.html', $this->user->lang('M_KASET'));
	}

	public function insert($data) {
		$sql = 'INSERT INTO ' . $this->m_plant . '' . $this->db->sql_build_array('INSERT', $data);
		$this->db->sql_query($sql);
	}

	public function show_data_all() {

		$per_page = $this->request->variable('this', $this->config ['topics_per_page']);
		$start = $this->request->variable('stat', 0);

		$sql = ' SELECT  *
			FROM ' . $this->m_plant;

		$result = $this->db->sql_query_limit($sql, $per_page, $start);

		while ($row = $this->db->sql_fetchrow($result)) {
			$this->template->assign_block_vars('plant', array(
			    'PLANT_ID' => $row['plant_id'],
			    'PLANT_NAME' => $row['plant_name'],
			   
			));
		}
	}
รูปภาพ

Re: insert ข้อมูลเข้าฐานข้อมูลไม่ได้ค่ะ

โพสต์แล้ว: 28/04/2016 9:41 am
โดย tsukasaz
มันบอกว่า user_add ต้องมีค่าเป็นตัวเลขครับ ตอนนี้ที่เห็นมันเป็นค่า ''

Re: insert ข้อมูลเข้าฐานข้อมูลไม่ได้ค่ะ

โพสต์แล้ว: 29/04/2016 10:53 am
โดย M034
ตอนนี้ทำได้แล้วค่ะ ขอบคุณมากนะคะ