Привет, ребята, я получаю сообщение об ошибке Неопределенная переменная см. Рис. Http://imgur.com/oJMbrYo
Что я хочу сделать, это загрузить изображение, а затем отправить его URL-адрес в базу данных. вот мой
контроллер профиля:
<?php class Profile extends CI_Controller { public function __construct() { parent::__construct(); $this->load->helper(array('url', 'html', 'form')); $this->load->library(array('session', 'form_validation')); $this->load->database(); $this->load->model('user_model'); } function index() { $details = $this->user_model->get_user_by_id($this->session->userdata('uid')); $data['uname'] = $details[0]->firstname . " " . $details[0]->lastname; $data['uemail'] = $details[0]->email; $this->load->view('profile_view', $data); } function delete() { $this->user_model->delete_row($this->session->userdata('uid')); redirect('Site/index'); } function update() { $this->user_model->update($this->input->post("name"), $this->session->userdata('uid')); $this->user_model->update($this->input->post("email"), $this->session->userdata('uid')); redirect('profile/index'); } public function index1() { $this->load->view('profile_view', array('error' => ' ' )); } public function do_upload() { $config['upload_path'] = './assets/img'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = 100; $config['max_width'] = 1024; $config['max_height'] = 768; $this->load->library('upload', $config); if ( ! $this->upload->do_upload('userfile')) { $error = array('error' => $this->upload->display_errors()); $this->load->view('profile_view', $error); } else { $data = array('upload_data' => $this->upload->data(), $this->session->userdata('uid')); $this->load->view('profile_view', $data); } } `}
вот мой профиль:
?> <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" type="text/css"> <link rel="stylesheet" href="<?php echo base_url('css/mystyle.css'); ?>" type="text/css"/> <link rel="stylesheet" type="text/css" href="<? echo base_url('assets/css/mystyle.css');?>" /> <link rel="stylesheet" href="<?php echo base_url()?>assets/css/mystyle.css" type="text/css"> <?php $autoload['helper'] = array('css_js');?> </head> <nav class="navbar navbar-inverse"> <div class="container-fluid"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <div class="mascot"> <a class="navbar-brand" href="#"> <img src="<?php echo base_url()?>assets/img/monstercode.png" alt="Green Monster Mascot" style="width:160px;height:32px;"></a> </div> </div> <div class="collapse navbar-collapse" id="myNavbar"> <ul class="nav navbar-nav"> <li class="active"><a href="<?php echo site_url('')?>">Home</a></li> <li><a href="<?php echo site_url('Site/sites')?>">Projects</a></li> <li><a href="<?php echo site_url('Site/developers')?>">Developers</a></li> <li><a href="<?php echo site_url('Site/employers')?>">Employers</a></li> <li><a href="#">Contact</a></li> <?php if ($this->session->userdata('login')){ ?> <li class="right nav navbar-nav navbar-right"><p class="navbar-text">Hello <?php echo $this->session->userdata('uname'); ?></p></li> <li class="right nav navbar-nav navbar-right"><a href="<?php echo base_url(); ?>index.php/home/logout">Log Out</a></li> <?php } else { ?> <li><a href="<?php echo base_url(); ?>index.php/login">Login</a></li> <li><a href="<?php echo base_url(); ?>index.php/signup">Signup</a></li> <?php } ?> </ul> </div> </div> </nav> <div class="container-fluid text-center"> <div class="row content"> <div class="col-sm-2 sidenav"> <div class="well"> <p>User Picture <br/><br/><br/><br/><br/><br/><br/><br/><br/></p> </div> <?php echo form_open_multipart('profile/do_upload'); ?> <?php echo form_upload('userfile'); ?><br /> <?php echo form_submit('upload', 'Upload');?> <?php echo form_close(); ?> <div class="well"> <p>User Info<br/> Name: <?php echo $uname; ?><br/> Email: <?php echo $uemail; ?> <br/><br/><br/><br/><br/><br/><br/><br/><br/></p> </div> </div> <div class="col-sm-8 text-left"> <div class="container"> <div class="row"> <div class="col-md-4"> <h4>Profile Summary</h4> <hr/> <form method="post" action="<?php echo site_url('profile/update');?>"> <p>Name: <input type="text" name='name'value="<?php echo $uname; ?>"></p> <p>Email: <input type="text" name='email' value="<?php echo $uemail; ?>"></p> <button type="submit" class="btn btn-default">Update</button> </form> <form method="post" action="<?php echo site_url('profile/delete');?>"> <button type="submit" class="btn btn-default">Delete</button> </form> <p>...</p> </div> <div class="col-md-8"> <p>lorem ipsum dolum</p> <p>lorem ipsum dolum</p> <p>lorem ipsum dolum</p> <p>...</p> </div> </div> </div> <hr> <h3>More User Info</h3> <p>Lorem ipsum...</p> </div> <div class="col-sm-2 sidenav"> <div class="well"> <p>Job Offers <br/><br/><br/><br/><br/><br/><br/><br/><br/></p> </div> <div class="well"> <p>Job Offers <br/><br/><br/><br/><br/><br/><br/><br/><br/></p> </div> </div> </div> </div> <script type="text/javascript" src="<?php echo base_url("assets/js/jquery-1.10.2.js"); ?>"></script> <script type="text/javascript" src="<?php echo base_url("assets/js/bootstrap.js"); ?>"></script> </body> </html>
Пожалуйста, дайте мне знать, что случилось с моим кодом. Благодарю.
Обновить модель
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class user_model extends CI_Model { function __construct() { parent::__construct(); } function get_user($email, $password) { $this->db->where('email', $email); $this->db->where('password', $password); $query = $this->db->get('user'); /* Select * from users where email = $_Post['email'] and password = $_post['password'] */ return $query->result(); } // get user function get_user_by_id($id) { $this->db->where('id', $id); //select id from users where id = $_Post['id'] $query = $this->db->get('user'); return $query->result(); } // insert function insert_user($data) { return $this->db->insert('user', $data); } //delete row function delete_row($id) { $this->db->where('id', $id); $this->db->delete('user'); } function update($uemail, $id) { $this->db->where('id', $id); $this->db->set('email', $uemail); $this->db->update('user'); } function add_image($uimage, $id){ $this->db->where('id', $id); $this->db->set('image', $uimage); $this->db->update('user'); } } ?>