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

时间:2016-01-26 03:19:03

标签: php html codeigniter uri segment

我想用不同的表更新数据。但它重定向到“你提交的URI已禁止字符”我有这样的表。请帮帮我:((

配方recipe

类别category

category_ingredient category_ingredient

成分ingredient

菜单menu

时间time

这是我的代码:

查看: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();

}

MODEL:products_model.php

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

1 个答案:

答案 0 :(得分:0)

查找您的不允许字符在您的网址中的内容?&=

然后转到你的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);