Codeigniter:当我尝试使用不同的表更新我的数据时,您提交的 URI 包含不允许的字符

Codeigniter: the URI you submitted have disallowed characters when i tried to update my data with different tables

我想用不同的表更新数据。但它重定向到 "The URI you submitted have disallowed characters"我有这样的表。请帮助我:((((

食谱

类别

category_ingredient

成分

菜单

时间

这是我的代码:

查看:edit_product.php

   <?php echo form_open('dashboard/save_edit_recipe/$product_id', 'class="form-horizontal" enctype="multipart/form-data"'); ?>
    <?php foreach($recipe_info as $row): ?>


    <input type="hidden" id="hide" name="recipe_id" value="<?php echo $row->recipe_id; ?>" class="form-control"><br/>      
    <div class="form-group">
        <div class="col-sm-10">
            <input class="form-control" type="text" name="r_name" placeholder="Recipe name" required value="<?php echo $row->r_name; ?>">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-10">
            <select required class="form-control" name="recipe_category">
                <?php $recipe_category = $this->products_model->getRecipeCategory($row->recipe_id); ?>
                <option value="" selected disabled>Select Recipe Category</option>
                <option value="All">All</option>
                <?php foreach($this->products_model->getCategory() as $cat): ?>
                    <?php if($cat->category_id == $recipe_category): ?>
                        <option selected value="<?php echo $cat->category_id ?>"><?php echo $cat->name ?></option>
                    <?php else: ?>
                        <option value="<?php echo $cat->category_id ?>"><?php echo $cat->name ?></option>
                    <?php endif; ?>
                <?php endforeach; ?>
            </select>

        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-10">
            <label>Pick Ingredients:</label>
            <div class="row" id="categoryIngredients" >
      <?php $ingredients  = $this->products_model->getRecipeIngridients($row->recipe_id); ?>
                <?php foreach($this->products_model->geIngredientsInCategory($recipe_category) as $ing): ?>
                    <div class="col-sm-3"><div class="checkbox"><label><input type="checkbox" name="ingredients[]" value="<?php echo $ing->ingredient_id ?>" <?php echo (in_array($ing->ingredient_id, $ingredients) >= -1 ? 'checked' : '') ?>><?php echo $ing->name ?></label></div></div>
                <?php endforeach; ?>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-10">
            <label>Type your Procedure</label><br/>
            <textarea id="recipeProcedure" name="recipe_procedure" rows="10" class="form-control" placeholder="Procedure"><?php echo $row->r_procedure ?></textarea>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-10">
            <select required class="form-control" name="cooking_time">
                <option value=""selected  disabled>Select Cooking time</option>
                <?php foreach($this->products_model->getRecipeCookingTime() as $time): ?>
                    <?php if($row->time_id == $time->time_id): ?>
                        <option selected value="<?php echo $time->time_id ?>"><?php echo $time->name ?></option>
                    <?php else: ?>
                        <option value="<?php echo $time->time_id ?>"><?php echo $time->name ?></option>
                  <?php endif; ?>
                 <?php endforeach; ?>
            </select>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-10">
            <textarea class="form-control" rows="5" placeholder="Description" name="r_description" required><?php echo $row->r_description; ?></textarea>
        </div>
    </div>
    <div class="form-group">
        <div class='col-sm-10'>
            <input  class='form-control' type="text" placeholder="Calories" name="calories" required value="<?php echo $row->r_cal ?>">
        </div>
    </div>
    <div class="form-group">
        <div class='col-sm-10'>
            <input  class='form-control' type="text" placeholder="Serving Size" name="serving_size" required value="<?php echo $row->r_serve ?>">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-10">
            <label>Upload Thumbnail</label>
            <input type="file" name="r_image" required>
            <div>
                <img style="width:50%;height:50%;"<?php echo img(base_url().$row->r_image); ?>
            </div>
        </div>
    </div>
    <div class='form-group'>
        <div class="col-sm-10">
            <button class="btn btn-lg btn-positive" type="submit"><i class="glyphicon glyphicon-ok"></i> Save Recipe</button>
        </div>
    </div>
    <?php endforeach; ?>
<?php echo form_close(); ?>

控制器:

function edit_product($product_id) 
{
    $data = array('recipe_info' => $this->products_model->getRcipe($this->uri->segment(3)),
                  'product_id'  => $this->uri->segment(3)
        );
    /*var_dump($data); die();*/
    $this->load->view('edit_product', $data);
}

public function save_edit_recipe()
{


    $this->load->model('products_model');
    $product_id= $this->input->post('recipe_id');
    $data = array(
                      'r_name'          => $this->input->post('r_name'),
                      'r_image'         => '',
                      'r_description'   => $this->input->post('r_description'),
                      'time_id'         => $this->input->post('cooking_time'),
                      'r_cal'           => $this->input->post('calories'),
                      'r_serve'         => $this->input->post('serving_size'),


    );
    $this->products_model->update_product($product_id,$data);

   $this->getRcipe();

}

型号:products_model.php

function getRcipe($recipe_id)
{
    $this->db->where('recipe_id', $recipe_id);
    $query = $this->db->get('recipe');
    return $query->result();
}

找到您的 url 中不允许使用的字符,可能是 ?&=

然后转到您的config.php,您可以在此处添加它们。

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';

后记重启或刷新服务器。

也在你的form_open

<?php echo form_open('dashboard/save_edit_recipe/$product_id', 'class="form-horizontal" enctype="multipart/form-data"'); ?>

$product_id 产品 ID 不正确

<?php echo form_open('dashboard/save_edit_recipe/' . $product_id, 'class="form-horizontal" enctype="multipart/form-data"'); ?>

如果需要使用mulitpart / form helper codeigniter one

<?php echo form_open_multipart('dashboard/save_edit_recipe' .'/'. $product_id, array('class' => 'form-horizontal'));?>

更新:

$this->products_model->update_product($this->uri->segment(3), $data);