Welcome Guest, Not a member yet? Register   Sign In
Save image path to database / edit function not editing entry but inserting new one
#11

[eluser]ede196620[/eluser]
Code:
protected $_primary_filter = 'intval';
$filter = $this->_primary_filter;

this is where the filter is

here is the input form:
Code:
<div class="modal-header">  
    <h3>&lt;?php echo empty($product->product_id) ? 'Add a new item' : 'Edit Item ' . $product->product_name; ?&gt;</h3>
</div>
<div class="modal-body">
    &lt;?php echo validation_errors(); ?&gt;
    &lt;?php echo form_open_multipart('site_user/product_c/edit'); ?&gt;
    &lt;?php echo form_hidden('id', $this->session->userdata('id')); ?&gt;
    <table class="table">  
        <tr>
            <td>Product Name</td>
            <td>  &lt;?php
                echo form_input('product_name', set_value('product_name', $product->product_name));
                
                ?&gt;
    
            </td>
        </tr>
        <tr>
            <td>Item Description:</td>
            <td>&lt;?php
                echo form_textarea('body', set_value('body', $product->body));
                ?&gt;</td>
        </tr>
      <tr>
            <td>Category</td>
            <td>            
                    &lt;?php
                    foreach ($category as $categorys) {
                       echo $categorys->category_name .form_radio('category_id', set_value('category', $categorys->category_id)).'</br>';
                    }

                    ?&gt;
            </td>
        </tr>
        <tr>
            <td>Sell/Trade</td>
            <td>
                &lt;?php
                $data_trade = array(
                    'name' => 'sell_or_trade',
                    'id' => 'trade',
                    'value' => 'trade',
                    'checked' => TRUE,
                    'style' => 'margin:10px',
                );
                 $data_sell = array(
                    'name' => 'sell_or_trade',
                    'id' => 'sell',
                    'value' => 'sell',
                    'style' => 'margin:10px',
                );
                ?&gt;
                &lt;?php echo 'Sell' . form_radio($data_sell); ?&gt;
                &lt;?php echo 'Trade' . form_radio($data_trade); ?&gt;
&lt;!--                &lt;input type="radio" name="sell_or_trade" id="sell" value="sell"&gt;
                &lt;input type="radio" name="sell_or_trade" id="trade" value="trade"&gt;--&gt;
            </td>
        </tr>
        <tr>
            <td><div class="text">Starting Price:</div></td>
            <td>
                <div class="text">      
&lt;!--                    &lt;input type="text" name="price" id="price" maxlength="30"&gt; --&gt;
                    &lt;?php
                    $data = array(
                        'name' => 'price',
                        'id' => '',
                        'value' => $product->price,
                        'maxlength' => '100',
                        'size' => '50',
                        'style' => 'width:50%',
                    );
                    echo form_input($data);
                    ?&gt;
                </div>  
            </td>      
        </tr>
        <tr>
            <td>Upload Photo:</td>
            <td>&lt;input type="file" name="img_path"  size="20" /&gt;&lt;/td>
        </tr>
        <tr>
            <td>&lt;?php echo form_submit('submit', 'Save', 'class="btn btn-primary"'); ?&gt;</td>
        </tr>
    </table>
    &lt;?php echo form_close(); ?&gt;
</div>

#12

[eluser]ede196620[/eluser]
so i looked at all of the code and the $id variable is empty when form validation runs true in controller edit function that's why it is not editing

Code:
$this->product->save($data, $id);
is empty after validation runs true everywhere else its not empty

Code:
if ($this->form_validation->run() == TRUE) {
            $data = $this->product->array_from_post(array('product_name', 'body', 'sell_or_trade', 'img_path', 'price', 'category_id', 'id', 'order'));
            $this->product->save($data, $id);
//            var_dump($id);
//            exit();
            redirect('site_user/product_c');
        }
but i daunt know why it is like that
#13

[eluser]InsiteFX[/eluser]
Do a view source in your web browser and see if the id is being assigned to your hidden input field.

You may need to get the CI Super object to use the sessions were your doing it.
#14

[eluser]Tim Brownlaw[/eluser]
In that last var_dump you provided I saw an entry for id...

Code:
array (size=8)
  'product_name' => string 'test product2222' (length=16)
  'body' => string 'test product description goes here' (length=34)
  'sell_or_trade' => string 'sell' (length=4)
  'img_path' => boolean false
  'price' => string '2222' (length=4)
  'category_id' => string '5' (length=1)
  'id' => string '1' (length=1)
  'order' => boolean false


Code:
'id' => string '1' (length=1)
It's a string with a value of 1...

What if you do the var_dump after your $id= filter($id);

So again, in that function do a var_dump

Code:
...
$id= filter($id);
var_dump($id);
...

Cause you got a value for id being passed into the function.

What you need to do is simply track back to where it starts to appear and where it stops appearing.
The trick is to narrow down where the issue is... Then you can find it and fix it Smile
There may be other issues, but just be methodical and you'll hunt it down...

Debugging issue like this can be fun and very educational so keep at it!

Cheers
Tim
#15

[eluser]ede196620[/eluser]
the id is assigned to the hidden input field
#16

[eluser]ede196620[/eluser]
HI Tim Brownlaw i did a war dump after the $id = $filter($id);
and it came up as null

i tracked the id and i found that it returns null when validation runs true and the data is inserted in to table using the array_from_post function
#17

[eluser]InsiteFX[/eluser]
The id should be var_dump($data['id']); and sent like below:

Code:
$this->product->save($data, $data['id']);

See if that works.

Also should this be like this?

Code:
$id = $filter;

// and not this
$id = $filter($id);

// if $filter(id) is a method then you need it like this
$id = $this->filter($id);
#18

[eluser]CroNiX[/eluser]
Do you have a validation rule set for the id field?




Theme © iAndrew 2016 - Forum software by © MyBB