douyin2883 2014-09-25 10:31 采纳率: 0%
浏览 18

Codeigniter:遇到PHP错误[重复]

This question already has an answer here:

I'm new to codeigniter.I'm able to add the data but unable to retrieve from data base to edit. Error shown below:

Severity: Notice Message: Undefined variable: mailshot Filename: mailshot/edit.php Line Number: 17

Help me with fixing error. Here is the code for Controller and the form followed:

public function edit() {

    /* Load model */
    $this -> load -> model('mailshot_model');
    /* End here */

        $data = array();

    if ($this -> input -> post()) {

        $data = array('title' => strip_tags(addslashes(trim($this -> input -> post('title')))),
        'url' => strip_tags(addslashes(trim($this -> input -> post('mailshoturl')))),
        'type' => strip_tags(addslashes(trim($this -> input -> post('type')))),
        'status' => strip_tags(addslashes(trim($this -> input -> post('status')))),
        'modified_by' => $this -> userid);

        $lastid = $this -> mailshot_model -> update_record($data);

        $links = array('msid' => $lastid,
        'ms_title' => strip_tags(addslashes(trim($this -> input -> post('title')))),
        'status' => strip_tags(addslashes(trim($this -> input -> post('status')))),
        'modified_by' => $this -> userid);


        /* Load Model */    
        $this -> load -> model('mailshotlinks_model');
    /* End here */
        $linkid = $this -> mailshotlinks_model -> update_record($links);
        if (isset($lastid)) {
            redirect(base_url() . 'mailshot', 'location');

        }
        //$lastid = $this -> mailshot_model -> add_record($data);
         else {
            $data = array("error" => 'Unable to create record.Please try agin ');
        }
    }

    $this -> layout -> view('mailshot/edit', $data);

}

<form class="mws-form" action="#" method="post" id="addevent_form"  enctype="multipart/form-data" >
                <div class="mws-form-inline">
                    <div class="mws-form-row">
                        <label class="mws-form-label">Mailshot Title:<span style="color: red">*</span></label>
                        <div class="mws-form-item">
                        <input type="text" name="title" id="title" value="<?php echo $mailshot['title']; ?>" class="medium">
                    </div>
                    </div>
                </div>
                <div class="mws-form-inline">
                    <div class="mws-form-row">
                        <label class="mws-form-label">URL:<span style="color: red">*</span></label>
                        <div class="mws-form-item">
                        <input type="text" name="mailshoturl" id="mailshoturl" value="<?php echo $mailshot['url']; ?>" class="medium">
                    </div>
                    </div>
                </div>



                <div class="mws-form-inline">
                    <div class="mws-form-row">
                        <label class="mws-form-label">Type:<span style="color: red">*</span></label>
                        <div class="mws-form-item">
                        <select name="type" id="type">
                            <option value="" selected="selected">Choose Mailshot Type</option>
                            <option value="paid" <?php if($mailshot['type'] == 'paid'){ echo "selected=selected"; } ?>>Paid</option>
                            <option value="free" <?php if($mailshot['type'] == 'free'){ echo "selected=selected"; } ?>>Free</option>


                        </select>
                        </div>
                    </div>
                </div>


                <div class="mws-form-inline">
        <div class="mws-form-row">
        <label class="mws-form-label">Status:<span style="color: red">*</span></label>
             <div class="mws-form-item">
              <select name="status" id="status">
                <option value="">--None--</option>
               <option value="Active" <?php if($mailshot['status']=='Active'){ echo "selected=selected"; }?>>Active</option>
              <option value="Inactive" <?php if($mailshot['status']=='Inactive'){ echo "selected=selected"; }?>>In Active</option>
              <option value="Disabled" <?php if($mailshot['status']=='Disabled'){ echo "selected=selected"; }?>>Disabled</option>
              </select>
             </div>
             </div>
      </div>

                <div class="mws-button-row">
                    <input type="submit" value="Submit" class="btn btn-success">
                </div>
            </form>
</div>
  • 写回答

1条回答 默认 最新

  • dongmie3526 2014-09-25 10:50
    关注

    Don't forget to use get() method after all your querys.

     function listAll() {
    
                $query = $this -> db -> query("select a.id as id ,
                 a.title as title,
                 a.url as url,
                 a.type as type,
                 a.type as status,
                 a.description as description,
                 a.status as status,
                 a.created_date as created_date,
                 a.modified_date as modified_date,
                 u.username AS created_by,
                 c.username AS modified_by from " . $this -> tablename . " as a 
                 LEFT JOIN tbl_admin u ON a.created_by = u.id
                 LEFT JOIN tbl_admin c ON a.modified_by = c.id order by a.id desc")->get();
                return $query -> result_array();
            }
    
            function listone($id) {
    
                $query = $this -> db -> query("SELECT
                 a.id as id ,
                 a.title as title,
                 a.url as url,
                 a.type as type,
                 a.type as status,
                 a.status as status,
                 a.modified_date as modified_date,
                 c.username AS modified_by
                 FROM " . $this -> tablename . " AS a
                 LEFT JOIN tbl_admin c ON a.modified_by = c.id
                 WHERE a.id=" . $id)->get();
    
                return $query -> result_array();
            }
    
            function get_record($id) {
                $query = $this -> db -> query("SELECT
                 a.id as id ,
                 a.title as title,
                 a.url as url,
                 a.type as type,
                 a.type as status,
                 a.status as status,
                 a.created_date as created_date,
                 a.modified_date as modified_date,
                 u.username AS created_by,
                 c.username AS modified_by
                 FROM " . $this -> tablename . " AS a
                 LEFT JOIN tbl_admin c ON a.modified_by = c.id
                 WHERE  a.id=" . $id)->get();
    
                return $query -> row_array();
            }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。