doudi5291 2018-06-13 17:40
浏览 15
已采纳

如何在ci中获取发布数据

i want to print post data in my login function with $this->input->post['username'];

I have a home controller given below :

<?php 
class Home extends CI_Controller{
    public function index(){
        $this->load->view("home/home_view");
    }
    public function Login(){
        echo $this->input->post['username'];
    }
}
?>

but its showing me null result but if i write print_r($_POST) instead of $this->input->post['username'] its showing me all data

this is my home view code

<!DOCTYPE html>
<html>
<head>
    <title>Home Page</title>
    <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/css/bootstrap.css">
</head>
<body>
    <div class="col-lg-2"></div>
    <div class="col-lg-8" style="min-height: 500px;box-shadow: 5px 5px 15px #000; margin-top: 50px;">
        <form method="post" action="<?php echo base_url(); ?>index.php/Home/Login">
            <table class="table table-stripped">
                <tr>
                    <th colspan="2">Login form</th>
                </tr>
                <tr>
                    <td>Username</td>
                    <td><input type="text" class="form-control" name="username"></td>
                </tr>
                <tr>
                    <td>Password</td>
                    <td><input type="password" name="password" class="form-control"></td>
                </tr>
                <tr>
                    <th colspan="2"><input type="submit" value="Submit" class="btn btn-primary"></th>
                </tr>
            </table>
        </form>
    </div>
    <div class="col-lg-2"></div>
</body>
</html>

i had auto loaded form helper and url helper

  • 写回答

2条回答 默认 最新

  • dougong5817 2018-06-13 18:16
    关注

    Hope this will help you :

    Use $this->input->post('username'); instead of $this->input->post['username'] :

    Your Login function should be like this :

    public function Login()
    {
        /* to print all field name do like this*/
        print_r($this->input->post());
    
        /* to print a particular field name do like this*/
        echo $this->input->post('username');
        echo $this->input->post('password');
    }
    

    Use site_url or base_url in form like this ( good practice) :

    <form method="post" action="<?php echo site_url('Home/Login'); ?>">
          ........
    </form>
    

    for more : https://www.codeigniter.com/user_guide/libraries/input.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)