簡體   English   中英

為什么我無法在 codeigniter 中更新記錄?

[英]Why I can't update the record in codeigniter?

我收到此錯誤,遇到一個 PHP 錯誤 嚴重性:注意

消息:嘗試獲取非對象的屬性“post_title”。

我無法將表單輸入打印在頁面上,也無法更新。 請幫忙! 所以,我嘗試更新每條記錄,只有藝術家用戶才能這樣做。 但我不知道如何在表單頁面上顯示個人帖子。 記錄正確保存並刪除但無法更新它們。

Controller

function editpost($post_id)//Edit post page
{
    if (!$this->session->Role =='member,artist') 
    {
        redirect(base_url() . 'login');
    }
    $data['success'] = 0;

    if( !empty($this->input->post('post_title')) ) {
        $data['post_title']             =  $this->input->post('post_title');
        $data['post']                   =  $this->input->post('post');
        $data['active']                 =  1;
                    /* >> file attach */




View
                    <form action="<?= base_url()?>starter/editpost/" method="post" class="justify- 
content-center"  enctype='multipart/form-data'>
                        <div class="form-group">
                            <label class="sr-only">Title</label>
                            <input type="text" class="form-control" placeholder="Title" 
name="post_title" value="<?php echo $post->post_title; ?>">
                        </div>
                        <div class="form-group">
                            <label class="sr-only">Description</label>
                            <textarea class="form-control" placeholder="Describe it" name="post" ><? 
php echo $post->post; ?></textarea>
                        </div>
                        <div class="row py-4">
    <div class="col-lg-6 mx-auto">

        <!-- Upload image input-->
<!-- File Button --> 

  <div class="col-md-5">
<input name="main_img[]" type="file" accept="image/x-png,image/gif,image/jpeg">
</div>

<br>
<br>

<p style="padding-top: 15px"><span>&nbsp;</span><input class="submit" type="submit" name="update" 
value="Publish" /></p>
                    </form>

直接使用變量,因為您只傳遞您從表單發布的值。

//like :
//for post_title 
<input type="text" class="form-control" placeholder="Title" 
name="post_title" value="<?php echo $post_title; ?>">
// for description
textarea class="form-control" placeholder="Describe it" name="post" ><? 
php echo $post; ?></textarea>

您不需要在控制器中傳遞發布數據,您可以在任何地方獲取發布數據

<input type="text" class="form-control" placeholder="Title" name="post_title" value="<?php echo ($this->input->post('post_title')!='')?$this->input->post('post_title'):''; ?>">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM