Codeigniter POST表单提交问题 [英] Codeigniter POST Form Submit Problems

查看:176
本文介绍了Codeigniter POST表单提交问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始学习CI和PHP,并想制作一个简单的CRUD应用程序。



我创建了一个添加记录的功能,但是当我提交表单中的数据时,Chrome会下载一个没有扩展名的文件。



Controller

 <?php 

类选项扩展了CI_Controller {

函数索引()
{
$ this-> load-> view('options_view');


$ b函数create()
{
$ data = array(
$ b $'name'=> $ ('name'),
'price'=> $ this-> input-> post('price'));

$ this-> data_model-> addItem($ data);
$ this-> index();
}

}

模型

 <?php 

class Data_model extends CI_Model {
function getAll(){
$ q = $ this-> db->查询(SELECT * FROM items);
if($ q-> num_rows()> 0){
foreach($ q-> result()as $ row){
$ data [] = $ row;
}
}
返回$ data;

$ b $ function addItem($ data){
$ this-> db-> insert('items',$ data);
return;
}
}
?>

查看

 < HTML>< HEAD>< /头><身体GT; 
< style type =text / css>
label {display:block;}
< / style>


< h2>建立< / h2>
<?php echo form_open('options / create'); ?>

< p>
< label for =name>名称< / label>< input type =textname =nameid =name/>
< / p>
< p>
< label for =name> Price< / label>< input type =textname =priceid =price/>
< / p>

< p>< input type =submitvalue =Submit/>< / p>

<?php echo form_close(); ?>

< / body>
< / html>

有什么我做错了吗?
没有错误弹出。表单已创建,但当我在文本框中添加数据并单击提交时,浏览器会下载一个创建文件。

可能是因为你不需要最后一行斜线?

 <?php echo form_open('options /创建/'); ?> 


I just started learning CI and PHP and wanted to make a simple CRUD application.

I created a function to add a record, but when i submit the data in the form, Chrome downloads a file with no extension.

Controller

<?php

class Options extends CI_Controller{

function index()
{
    $this->load->view('options_view');

}

function create()
{
    $data = array(

        'name' => $this->input->post('name'),
        'price' => $this->input->post('price'));

    $this->data_model->addItem($data);
    $this->index();
}

}

Model

<?php

class Data_model extends CI_Model {
function getAll() {
$q = $this->db->query("SELECT * FROM items");
if($q->num_rows() >0){
    foreach($q->result() as $row){
        $data[]=$row;
    }
}
return $data;
}

function addItem($data){
    $this->db->insert('items', $data);
    return;
}
}
?>

View

<html><head></head><body>
<style type="text/css">
label {display: block;}
</style>


<h2>Create</h2>
<?php echo form_open('options/create'); ?>

<p>
    <label for="name">Name</label><input type="text" name="name" id="name" />
</p>
<p>
    <label for="name">Price</label><input type="text" name="price" id="price" />
</p>

<p><input type="submit" value="Submit" /></p>

<?php echo form_close(); ?>

</body>
</html>

Is there something that i did wrong? No errors pop out. The form is created, but when i add data in the textboxes and click submit, the browser dowloands a "Create" file.

解决方案

Could it be that you don't need the last slash in that line?

<?php echo form_open('options/create/'); ?>

这篇关于Codeigniter POST表单提交问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆