Insert ข้อมูล แล้ว error

สำหรับผู้ที่ เริ่มต้น Programming - PHP มีอะไร แนะนำ หรือข้อสงสัยต้องบอร์ด นี้ คนที่มีความรู้ แบ่งปันคนอื่นบ้างนะ ปัญหาการเขียนโปรแกรม แบบ OOP Session Cookies php network

Moderator: mindphp, ผู้ดูแลกระดาน

M034
PHP Super Member
PHP Super Member
โพสต์: 258
ลงทะเบียนเมื่อ: 28/03/2016 10:21 am
ติดต่อ:

Insert ข้อมูล แล้ว error

โพสต์ที่ยังไม่ได้อ่าน โดย M034 »

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

<?php 
namespace mm\set\controller;

use Symfony\Component\DependencyInjection\Container;

class pest {
	
var $u_action;

	public function __construct(\phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user, \phpbb\controller\helper $helper, $root_path, $php_ext, $m_pest
	) {
		$this->config = $config;
		$this->db = $db;
		$this->request = $request;
		$this->template = $template;
		$this->user = $user;
		$this->helper = $helper;
		$this->root_path = $root_path;
		$this->php_ext = $php_ext;
		$this->m_pest = $m_pest;

		$this->user->add_lang_ext('mm/set', 'simple');
	}

	public function pest($action) {
		$error = array();

		switch ($action) {
			case 'show_pest':

				$this->show_pest_all();

				$this->template->assign_vars(array(
				    'SHOW_PEST' => true,
				    'U_ADDPEST' => $this->helper->route('mm_pest_controller', array('action' => 'add_pest'))
				));
				break;

			case 'add_pest':

				$pest = array(
				    'pest_name'=> $this->request->variable('pest_name', '', true),
				    'pest_detail'=> $this->request->variable('pest_detail', '', true),
				    'user_add_id'=> 0,
				    'time_add'=> time(),
				    'user_edit_id'=>0,
				    'time_edit'=> 0,
			
				);

				if ($this->request->is_set_post('submit')) {

					$error = $this->validate_input($pest);

					if (!$error) {

						$insert_ok = $this->insert($pest);

						if ($insert_ok) {

							$mode_url_error = $this->helper->route('mm_pest_controller', array('action' => 'show_pest'));
							meta_refresh(3, $mode_url_error);
							trigger_error('<a href=" ' . $mode_url_error . ' ">' . $this->user->lang['INSERT_OK'] . '</a>', E_USER_WARNING);
						}
					}
				}

				$this->template->assign_vars(array(
				    'ERROR' => (sizeof($error)) ? implode('<br/>', $error) : '',
				    'SHOW_FORM_PEST' => true,
				    'A_ACTION' => $this->helper->route('mm_pest_controller', array('action' => 'add_pest'))
				));

				break;

			default:
				break;
		}
		$page_title = $this->user->lang('pest');
		$this->template->assign_block_vars('navlinks', array(
		    'FORUM_NAME' => $page_title,
		    'U_VIEW_FORUM' => $this->helper->route('mm_set_controller', array('name' => 'mm')),
		));
		return $this->helper->render('pest.html', $this->user->lang('M_KASET'));
	}
public function insert($pest) {
		$sql ='INSERT INTO' . $this->m_pest. ''. $this->db->sql_build_array('INSERT',$pest);
		$this->db->sql_query($sql);
		return true;
	}

	public function validate_input($pest) {

		$error = array();

		if (empty($pest['pest_name'])) {
			$error[] = $this->user->lang ['ERROR_PEST_NAME'];
		}


		return $error;
	}

	public function show_pest_all() {

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



		$sql_arr = array(
		    'SELECT' => '*',
		    'FROM' => array(
			$this->m_pest => 'pe'
		    ),
		);

		$sql = $this->db->sql_build_query('SELECT', $sql_arr);

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

		while ($row = $this->db->sql_fetchrow($result)) {
			$this->template->assign_block_vars('pest', array(
			    'PEST_ID'=> $row['pest_id'],
			    'PEST_NAME'=> $row['pest_name'],
			    'PEST_DETAIL'=> $row['pest_detail'],
			    'USER_ADD_ID'=> $row ['user_add_id'],
			    'TIME_ADD'=> $row['time_add'],
			    'USER_EDIT_ID'=> $row['user_edit_id'],
			    'TIME_EDIT'=> $row['time_edit'],

			));
		}
	}
แต่เหมือนมันเพิ่มข้อมูลไปอีกตารางหนึ่งค่ะ แต่ไม่เข้าตารางที่เราต้องการ
รูปภาพ
ภาพประจำตัวสมาชิก
thatsawan
PHP VIP Members
PHP VIP Members
โพสต์: 28508
ลงทะเบียนเมื่อ: 31/03/2014 10:02 am
ติดต่อ:

Re: Insert ข้อมูล แล้ว error

โพสต์ที่ยังไม่ได้อ่าน โดย thatsawan »

$sql =' INSERT INTO ' . $this->m_pest. ''. $this->db->sql_build_array('INSERT',$pest);

เว้นช่องว่าง INSERT INTO_ หน่อย มันติดกับชื่อตาราง ไม่ถูกต้องตาม SQL
M034
PHP Super Member
PHP Super Member
โพสต์: 258
ลงทะเบียนเมื่อ: 28/03/2016 10:21 am
ติดต่อ:

Re: Insert ข้อมูล แล้ว error

โพสต์ที่ยังไม่ได้อ่าน โดย M034 »

ใส่วรรคแล้วค่ะ แต่ก็ยังติด error
M034
PHP Super Member
PHP Super Member
โพสต์: 258
ลงทะเบียนเมื่อ: 28/03/2016 10:21 am
ติดต่อ:

Re: Insert ข้อมูล แล้ว error

โพสต์ที่ยังไม่ได้อ่าน โดย M034 »

ตอนนี้แก้ไขได้แล้วนะคะ เป็นเพราะไฟล์ yml เรียงข้อมูลตารางไม่ถูกต้องค่ะ ขอบคุณนะคะ
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 55