Code Iginiter Error 'The address wasn't understood' - php

i' newbie code iginiter 3 with mysql database, and xampp v3.2 .
Error 'The address wasn't understood' when i click login button.
help me ...
this config
<code>`enter code here`
$config['base_url'] = 'localhost:8087/hris/';
$config['index_page'] = 'login.php';
</code>
and my route.php
<code>
$route['default_controller'] = 'user_authentication';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
</code>
how to fix this error....
user_authentication.php
Class User_Authentication extends CI_Controller
{
//session_start(); //we need to start session in order to access it through CI
public function __construct()
{
parent::__construct();
// Load form helper library
$this->load->helper('form');
// Load form validation library
$this->load->library('form_validation');
// Load session library
$this->load->library('session');
// Load database
$this->load->model('login_database');
}
// Show login page
public function index()
{
$this->load->view('login');
}
// Show registration page
public function user_registration_show()
{
$this->load->view('registration_form');
}
// Validate and store registration data in database
public function new_user_registration()
{
// Check validation for user input in SignUp form
$this->form_validation->set_rules('username', 'Username','trim|required|xss_clean');
$this->form_validation->set_rules('email_value', 'Email', 'trim|required|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('registration_form');
} else
{
$data = array(
'user_name' => $this->input->post('UserID'),
'user_email' => $this->input->post('email_value'),
'user_password' => $this->input->post('password')
);
$result = $this->login_database->registration_insert($data);
if ($result == TRUE)
{
$data['message_display'] = 'Registration Successfully !';
$this->load->view('login_form', $data);
} else {
$data['message_display'] = 'Username already exist!';
$this->load->view('registration_form', $data);
}
}
}
// Check for user login process
public function user_login_process()
{
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
if ($this->form_validation->run() == FALSE)
{
if(isset($this->session->userdata['logged_in']))
{
$this->load->view('admin_page');
}else{
$this->load->view('login_form');
}
} else {
$data = array(
'username' => $this->input->post('username'),
'password' => $this->input->post('password')
);
$result = $this->login_database->login($data);
if ($result == TRUE)
{
$username = $this->input->post('username');
$result = $this->login_database->read_user_information($username);
if ($result != false)
{
$session_data = array(
'username' => $result[0]->user_name,
'email' => $result[0]->user_email,
);
// Add user data in session
$this->session->set_userdata('logged_in', $session_data);
$this->load->view('admin_page');
}
} else {
$data = array(
'error_message' => 'Invalid Username or Password'
);
$this->load->view('login_form', $data);
}
}
}
// Logout from admin page
public function logout()
{
// Removing session data
$sess_array = array(
'username' => ''
);
$this->session->unset_userdata('logged_in', $sess_array);
$data['message_display'] = 'Successfully Logout';
$this->load->view('login_form', $data);
}
}
?>
this models login_database.php
Class Login_Database extends CI_Model
{
// Insert registration data in database
public function registration_insert($data)
{
// Query to check whether username already exist or not
$condition = "user_name =" . "'" . $data['user_name'] . "'";
$this->db->select('*');
$this->db->from('user_login');
$this->db->where($condition);
$this->db->limit(1);
$query = $this->db->get();
if ($query->num_rows() == 0)
{
// Query to insert data in database
$this->db->insert('user_login', $data);
if ($this->db->affected_rows() > 0)
{
return true;
}
} else {
return false;
}
}
// Read data using username and password
public function login($data)
{
$condition = "user_name =" . "'" . $data['username'] . "' AND " . "user_password =" . "'" . $data['password'] . "'";
$this->db->select('*');
$this->db->from('user_login');
$this->db->where($condition);
$this->db->limit(1);
$query = $this->db->get();
if ($query->num_rows() == 1) {
return true;
} else {
return false;
}
}
// Read data from database to show data in admin page
public function read_user_information($username) {
$condition = "user_name =" . "'" . $username . "'";
$this->db->select('*');
$this->db->from('user_login');
$this->db->where($condition);
$this->db->limit(1);
$query = $this->db->get();
if ($query->num_rows() == 1) {
return $query->result();
} else {
return false;
}
}
}
this view ( login.php )
$this->load->helper('form');
if (isset($this->session->userdata['logged_in'])) {
header("location: http://localhost/login/index.php/user_authentication/user_login_process");
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Global stylesheets -->
<link href="https://fonts.googleapis.com/css?family=Roboto:400,300,100,500,700,900" rel="stylesheet" type="text/css">
<link href="assets/css/icons/icomoon/styles.css" rel="stylesheet" type="text/css">
<link href="assets/css/minified/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="assets/css/minified/core.min.css" rel="stylesheet" type="text/css">
<link href="assets/css/minified/components.min.css" rel="stylesheet" type="text/css">
<link href="assets/css/minified/colors.min.css" rel="stylesheet" type="text/css">
<!-- /global stylesheets -->
<!-- Core JS files -->
<script type="text/javascript" src="assets/js/plugins/loaders/pace.min.js"></script>
<script type="text/javascript" src="assets/js/core/libraries/jquery.min.js"></script>
<script type="text/javascript" src="assets/js/core/libraries/bootstrap.min.js"></script>
<script type="text/javascript" src="assets/js/plugins/loaders/blockui.min.js"></script>
<!-- /core JS files -->
<!-- Theme JS files -->
<script type="text/javascript" src="assets/js/plugins/forms/styling/uniform.min.js"></script>
<script type="text/javascript" src="assets/js/core/app.js"></script>
<script type="text/javascript" src="assets/js/pages/login.js"></script>
<!-- /theme JS files -->
</head>
<body>
<!-- Main navbar -->
<div class="navbar navbar-inverse">
<div class="navbar-header">
<a class="navbar-brand" href="index.html"><img src="assets/images/logo_light.png" alt=""></a>
<ul class="nav navbar-nav pull-right visible-xs-block">
<li><a data-toggle="collapse" data-target="#navbar-mobile"><i class="icon-tree5"></i></a></li>
</ul>
</div>
</div>
<!-- /main navbar -->
<!-- Page container -->
<div class="page-container login-container">
<!-- Page content -->
<div class="page-content">
<!-- Main content -->
<div class="content-wrapper">
<!-- Content area -->
<div class="content">
<?php
echo form_open('user_authentication/user_login_process');
?>
<!-- Advanced login -->
<form action="" method="post">
<div class="panel panel-body login-form">
<div class="text-center">
<div class="icon-object border-slate-300 text-slate-300"><i class="icon-reading"></i></div>
<h5 class="content-group">Login to your account <small class="display-block">Your credentials</small></h5>
</div>
<div class="form-group has-feedback has-feedback-left">
<input type="text" class="form-control" placeholder="Username" name="userid" id="userid" required>
<div class="form-control-feedback">
<i class="icon-user text-muted"></i>
</div>
</div>
<div class="form-group has-feedback has-feedback-left">
<input type="text" class="form-control" placeholder="Password" name="pass" id="pass" required>
<div class="form-control-feedback">
<i class="icon-lock2 text-muted"></i>
</div>
</div>
<div class="form-group login-options">
<div class="row">
<div class="col-sm-6">
<label class="checkbox-inline">
<input type="checkbox" class="styled" checked="checked">
Remember
</label>
</div>
<div class="col-sm-6 text-right">
Forgot password?
</div>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn bg-blue btn-block">Login <i class="icon-arrow-right14 position-right"></i></button>
</div>
<?php echo form_close(); ?>
<div class="content-divider text-muted form-group"><span>Don't have an account?</span></div>
Sign up
</div>
</form>
<!-- /advanced login -->
</div>
<!-- /content area -->
</div>
<!-- /main content -->
</div>
<!-- /page content -->
</div>
<!-- /page container -->
</body>
</html>
</pre></code>

try to change your form open in to this
<?php
echo form_open(base_url('User_Authentication/user_login_process'));
?>

For anyone who face the problem of The address wasn't understood when clicking a link for example, just make sure to add http:// to the $config['base_url'] value, in the case of the question above, you should replace :
$config['base_url'] = 'localhost:8087/hris/';
by
$config['base_url'] = 'http://localhost:8087/hris/';
Hope this help :)

Related

How to Include Files by ID: MY shop the LAST Setting

My website the products are identified by the msql id that dynamically loads each page
<?php
session_start();
require_once('./inc/config.php');
require_once('./inc/helpers.php');
if(isset($_GET['product']) && !empty($_GET['product']) && is_numeric($_GET['product']))
{
$sql = "SELECT p.*,pdi.img from tenis_femininos p
INNER JOIN tenis_feminios_images pdi ON pdi.product_id = p.id WHERE pdi.is_featured =:featured AND p.id =:productID";
$handle = $db->prepare($sql);
$params = [
':featured'=>1,
':productID' =>$_GET['product'],
];
$handle->execute($params);
if($handle->rowCount() == 1 )
{
$getProductData = $handle->fetch(PDO::FETCH_ASSOC);
$imgUrl = PRODUCT_IMG_URL.str_replace(' ','-',strtolower($getProductData ['sku']))."/".$getProductData ['img'];
}
else
{
$error = '404! No record found';
}
}
else
{
$error = '404! No record found';
}
if(isset($_POST['add_to_cart']) && $_POST['add_to_cart'] == 'add to cart')
{
$productID = intval($_POST['product_id']);
$productQty = intval($_POST['product_qty']);
$entraSku = validate_input($_POST['pega_sku']);
$entraCor = validate_input($_POST['pega_cor']);
$entraSize = validate_input($_POST['pega_size']);
$sql = "SELECT p.*,pdi.img from tenis_femininos p
INNER JOIN tenis_feminios_images pdi ON pdi.product_id = p.id WHERE pdi.is_featured =:featured AND p.id =:productID";
$prepare = $db->prepare($sql);
$params = [
':featured'=>1,
':productID' =>$productID,
];
$prepare->execute($params);
$fetchProduct = $prepare->fetch(PDO::FETCH_ASSOC);
$calculateTotalPrice = number_format($productQty * $fetchProduct['price'],2);
$cartArray = [
'product_id' =>$productID,
'qty' => $productQty,
'sku' => $entraSku,
'color' => $entraCor,
'medida' => $entraSize,
'product_name' =>$fetchProduct['product_name'],
'product_price' => $fetchProduct['price'],
'total_price' => $calculateTotalPrice,
'product_img' =>$fetchProduct['img']
];
if(isset($_SESSION['cart_items']) && !empty($_SESSION['cart_items']))
{
$productIDs = [];
foreach($_SESSION['cart_items'] as $cartKey => $cartItem)
{
$productIDs[] = $cartItem['product_id'];
if($cartItem['product_id'] == $productID)
{
$_SESSION['cart_items'][$cartKey]['qty'] = $productQty;
$_SESSION['cart_items'][$cartKey]['sku'] = $entraSku;
$_SESSION['cart_items'][$cartKey]['color'] = $entraCor;
$_SESSION['cart_items'][$cartKey]['medida'] = $entraSize;
$_SESSION['cart_items'][$cartKey]['total_price'] = $calculateTotalPrice;
break;
}
}
if(!in_array($productID,$productIDs))
{
$_SESSION['cart_items'][]= $cartArray;
}
$successMsg = true;
}
else
{
$_SESSION['cart_items'][]= $cartArray;
$successMsg = true;
}
}
$pageTitle = 'Cool T-Shirt Shop Single Product Page';
$metaDesc = 'Demo PHP shopping cart get tenis_femininos from database';
?>
<!DOCTYPE html>
<html lang="pt-br"><head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="shortcut icon" href="https://glarza.com/favicon.ico.webp" type="image/x-icon"/>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons#1.3.0/font/bootstrap-icons.css">
<title><?php echo (isset($pageTitle)?$pageTitle:'PHP Shopping Cart')?></title>
<meta name="description" content="<?php echo (isset($metaDesc)?$metaDesc:'Demo PHP Shopping Cart')?>">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script type="text/javascript" src="https://cdn.stormize.com/framework/99571.js"></script><!--<![endif]-->
<script type="text/javascript">
<!-- FUCTION PELO TYPE BUTTON --><!-- FUCTION PELO TYPE BUTTON --><!-- FUCTION PELO TYPE BUTTON --><!-- FUCTION PELO TYPE BUTTO
//-->
function switchVisible() {}
</script>
<style type="text/css">
#selectable img {
margin: 5px;
padding: 5px;
border: 2px solid #ffffff;
}
.selected-items {
border: 2px solid #ff0000;
line-height: 32px;
}
</style>
</head>
<body>
<div class="container">
<div class="row mt-2 mb-2">
<div class="col-md-12 col-xs-12">
<h1>
Cool T-Shirt Shop
</h1>
</div>
</div>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
</ul>
<div class="form-inline my-2 my-lg-0">
</div>
</nav>
<?php //ESTE É O PHP DO CHECKOUT COM ALGUMA MODIFICAÇÕES PRA FUNCIONAR AQUI;
//pre($_SESSION);
if(isset($_POST['submit']))
{
if(isset($_POST['first_name'],$_POST['last_name'],$_POST['email'],$_POST['rua'],$_POST['bairro'],$_POST['cidade'],$_POST['uf']) && !empty($_POST['first_name']) && !empty($_POST['last_name']) && !empty($_POST['email']) && !empty($_POST['rua']) && !empty($_POST['bairro']) && !empty($_POST['cidade']) && !empty($_POST['uf']))
{
$firstName = $_POST['first_name'];
if(filter_var($_POST['email'],FILTER_VALIDATE_EMAIL) == false)
{
$errorMsg[] = 'Please enter valid email address';
}
else
{
//validate_input is a custom function
//you can find it in helpers.php file
$firstName = validate_input($_POST['first_name']);
$lastName = validate_input($_POST['last_name']);
$email = validate_input($_POST['email']);
$telefone = validate_input($_POST['telefone']);
$cep = validate_input($_POST['cep']);
$rua = validate_input($_POST['rua']);
$numero = validate_input($_POST['numero']);
$complemento = validate_input($_POST['complemento']);
$bairro = validate_input($_POST['bairro']);
$cidade = validate_input($_POST['cidade']);
$uf = validate_input($_POST['uf']);
$sql = 'insert into orders (first_name, last_name, email, telefone, cep, rua, numero, complemento, bairro, cidade, uf, order_status,created_at, updated_at) values (:fname, :lname, :email, :telefone, :cep, :rua, :numero, :complemento, :bairro, :cidade, :uf, :order_status,:created_at, :updated_at)';
$statement = $db->prepare($sql);
$params = [
'fname' => $firstName,
'lname' => $lastName,
'email' => $email,
'telefone' => $telefone,
'cep' => $cep,
'rua' => $rua,
'numero' => $numero,
'complemento' => $complemento,
'bairro' => $bairro,
'cidade' => $cidade,
'uf' => $uf,
'order_status' => 'confirmed',
'created_at'=> date('Y-m-d H:i:s'),
'updated_at'=> date('Y-m-d H:i:s')
];
$statement->execute($params);
if($statement->rowCount() == 1)
$pageTitle = 'Demo PHP Shopping cart checkout page with Validation';
$metaDesc = 'Demo PHP Shopping cart checkout page with Validation';
?>
<?php if(isset($getProductData) && is_array($getProductData)){?>
<?php if(isset($successMsg) && $successMsg == true){?>
<div class="row mt-3">
<div class="col-md-12">
<div class="alert alert-success alert-dismissible">
<button type="button" class="close" data-dismiss="alert">×</button>
<img src="<?php echo $imgUrl ?>" class="rounded img-thumbnail mr-2" style="width:40px;"><?php echo $getProductData['product_name']?> is added to cart. View Cart
</div>
</div>
</div>
<?php }?>
<div class="row mt-3">
<div class="col-md-5">
<img src="<?php echo $imgUrl;?>">
</div>
<div class="col-md-7">
<h1><?php echo $getProductData['product_name']?></h1>
<p><?php echo $getProductData['short_description']?></p>
<h4>R$<?php echo $getProductData['price']?></h4>
<div class="selectable">
<?php include('layouts/select.php');?>
</div>
</div>
<div class="row mt-3">
</div>
<?php
}
?><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script><script src="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script><script src="js/custom.js"></script> </div><script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js'></script><script src='https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js'></script></body></html>
the product page has an php include
<?php include('layouts/select.php');?>
I need to include the file layouts - colors and specific measures for each product:
layouts / id1.php
layouts / id2.php
layouts / id3.php
This is my layouts/selects file:
<? php
$id = echo $getProductData['id'];
if($id['acc']=='1') {
include('layouts/id1.php');}
if($id['acc']=='2') {
include('layouts/id2.php');}
if($id['acc']=='2') {
include('layouts/id3.php');}
?>
echo I get each product id
<?php echo $getProductData['id']?>
My problem ... I need to insert this id inside this include file.
<?php include('layouts/select.php');?>
or insert the id value in the specific php include, for example id = 1
<?php include('layouts/id1.php');?>
So I want to open the include file by selected id. Of course if there is another solution I accept it :)
<?php
include("layouts/id".$getProductData['id'].".php");
?>

CodeIgniter Login Controller Form Authentication Not working

Hi I am encountering a strange error ,I have a small application having few pages for reports and entering logs ,the login authentication form is working perfectly fine on another host computer ,I have simply replicated the data to a new host computer ,the Login form gets refreshed after clicking on submit button ,I am not sure what is the reason behind I tried multiple ways to dig out the actual reason somehow I am failed here is my code data
Views/login.php
'''
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ITS</title>
<!-- CSS -->
<link rel="stylesheet" href="<?php echo base_url() ?>frontend/css?family=Roboto:400,100,300,500">
<link rel="stylesheet" href="<?php echo base_url() ?>frontend/css/bootstrap.min.css">
<link rel="stylesheet" href="<?php echo base_url() ?>frontend/css/font-awesome.min.css">
<link rel="stylesheet" href="<?php echo base_url() ?>frontend/css/form-elements.css">
<link rel="stylesheet" href="<?php echo base_url() ?>frontend/css/style.css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- Favicon and touch icons -->
<link rel="shortcut icon" href="assets/ico/favicon.png">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png">
</head>
<body>
<!-- Top content -->
<div class="top-content">
<div class="inner-bg">
<div class="container">
<div class="row">
<div class="col-sm-8 col-sm-offset-2 text">
<h1><strong>ITS</strong></h1>
</div>
</div>
<div class="row">
<div class="col-sm-6 col-sm-offset-3 form-box">
<div class="form-top">
<div class="form-top-left">
<h3>Login</h3>
<p>Enter your username and password to log on:</p>
</div>
<div class="form-top-right">
<i class="fa fa-lock"></i>
</div>
</div>
<div class="form-bottom">
<form action="<?php echo base_url('index.php/Login');?>" method="post" class="login-form">
<div class="form-group">
<label class="sr-only" for="form-username">Username</label>
<input type="text" name="username" placeholder="Username..." class="form-username form-control" id="form-username">
</div>
<div class="form-group">
<label class="sr-only" for="form-password">Password</label>
<input type="password" name="password" placeholder="Password..." class="form-password form-control" id="form-password">
</div>
<button type="submit" class="btn">Sign in!</button>
</form>
</div>
</div>
</div>
<div class="row">
</div>
</div>
</div>
</div>
<!-- Javascript -->
<script src="<?php echo base_url() ?>frontend/js/jquery-1.11.1.min.js"></script>
<script src="<?php echo base_url() ?>frontend/js/bootstrap.min.js"></script>
<script src="<?php echo base_url() ?>frontend/jquery.backstretch.min.js"></script>
<script src="<?php echo base_url() ?>frontend/scripts.js"></script>
<!--[if lt IE 10]>
<script src="assets/js/placeholder.js"></script>
<![endif]-->
</body>
Controller/Login.php
<?php
class Login extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->library('form_validation');
$this->load->helper('form');
$this->load->helper('url');
$this->load->model('main_db');
}
function index()
{
$this->form_validation->set_rules('username', 'username', 'required|trim|xss_clean|max_length[100]');
$this->form_validation->set_rules('password', 'password', 'required|trim|xss_clean|max_length[100]');
$this->form_validation->set_error_delimiters('<br /><span class="error">', '</span>');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('login');
}
else
{
$res=$this->main_db->get_table_where("users",array("username"=>set_value('username')));
if($res)
{
$form_data = array(
'username' => set_value('username'),
'password' => set_value('password'),
);
$res=$this->main_db->auth($form_data);
//print_r($res);
if ($res != "")
{
$uid = set_value('username');
$role = $res['role_id'];
$user_region= $res['region'];
$parameters['id']=$role;
$urole=$this->main_db->get_table_where('user_role',$parameters);
$con1 =$this->main_db->get_table_data('configuration');
$org_name = $con1[0]->Organization_Name;
$org_address = $con1[0]->Organization_Address;
$org_phone = $con1[0]->Organization_Phone;
$ur = $urole[0]->role;
$this->session->set_userdata('username', set_value('username'));
$this->session->set_userdata('user_role', $ur);
$this->session->set_userdata('user_region', $user_region);
$this->session->set_userdata('org_name', $org_name);
$this->session->set_userdata('org_address', $org_address);
$this->session->set_userdata('org_phone', $org_phone);
redirect('/mainpage/callregister');
}
else
{
$data["error"]="Password is incorrect.";
$this->load->view('login',$data);
}
}
else
{
$data["error"]="Username doesnot exist.";
$this->load->view('login',$data);
}
}
}
}
?>
Model/main_db.php
<?php
class Main_db extends CI_Model {
var $debug = 1;
var $user_region="";
var $urole ="";
function __construct()
{
// Call the Model constructor
parent::__construct();
$this->load->database();
$this->load->library('custom_library');
$this->user_region =$this->session->userdata("user_region");
$this->urole =$this->session->userdata("user_role");
}
function Get_Row($qu,$parameters=array())
{
$dbquery = $this->db->query($qu, $parameters);
$ret = $dbquery->row_array();
return $ret;
}
///////////////////////////////////////////////
function auth($formdata)
{
$uid = $formdata['username'];
$pwd = $formdata['password'];
$qu="select * from users where username=? and password=?";
$parameters = array($uid, $pwd);
$ret2 = $this->Get_Row($qu,$parameters);
if (count($ret2) > 0)
{
$ret=$ret2;
}
else
{
$ret="";
}
return $ret;
}
////////////////////////////////////////////////////
function get_table_data($table)
{
$query = $this->db->get($table);
$res=$query->result();
return $res;
}
///////////////////////////////////////////////////////
function get_table_where($table,$parameters=array())
{
$query = $this->db->get_where($table,$parameters);
$res=$query->result();
return $res;
}
////////////////////////////////////////////////////////
////////////////////////////////////////////////////
function insert_table($table,$data)
{
return $this->db->insert($table,$data);
}
//////////////////////////////////////////////////////////////
function update_table_where($table,$data=array(),$parameters=array())
{
$this->db->where($parameters);
$this->db->update($table, $data);
return $this->db->affected_rows();
}
///////////////////////////////////////////////////////////////
function get_paginited_data($table, $start,$limit)
{
$query = $this->db->get($table, $limit, $start);
$res=$query->result();
return $res;
}
function get_paginited_where($table,$param=array(), $start,$limit)
{
$query = $this->db->get_where($table,$param, $limit, $start);
//echo $this->db->last_query();
$res=$query->result();
return $res;
}
function get_role_menus($role)
{
$query = "SELECT * FROM role_permissions a inner join modules b on a.module_id=b.module_id and a.role='$role'";
$query=$this->db->query($query);
$res=$query->result();
return $res;
}
function get_submodules($parent_id,$role)
{
$query = "SELECT * FROM submodules_permissions a inner join sub_modules b on a.module_id=b.module_id and a.role='$role' and a.parent_id='$parent_id' order by b.visible_name";
$query=$this->db->query($query);
$res=$query->result();
return $res;
}
function get_menu_details($id,$child)
{
if($child==0)
{
$table="modules";
}
else
{
$table="sub_modules";
}
$qu="Select * from $table where module_id='$id'";
$query=$this->db->query($qu);
$r=$query->result();
return $r[0];
}
function count_childs($parent_id)
{
$qu="select count(*) as total from sub_modules where parent_id='$parent_id'";
$query=$this->db->query($qu);
$r=$query->result();
return $r[0]->total;
}
function get_child_menus($parent_id)
{
$qu="Select * from sub_modules where parent_id='$parent_id'";
$query=$this->db->query($qu);
$r=$query->result();
return $r;
}
function check_menu_permissions($id,$role,$child)
{
if($child==0)
{
$table="role_permissions";
}
else
{
$table="submodules_permissions";
}
$qu="Select count(*) as total from $table where module_id='$id' and role='$role'";
$query=$this->db->query($qu);
$r=$query->result();
return $r;
}
function delete_user_modules($role)
{
$qu="delete from role_permissions where role='$role'";
$query=$this->db->query($qu);
return $query;
}
function delete_user_submodules($role)
{
$qu="delete from submodules_permissions where role='$role'";
$query=$this->db->query($qu);
return $query;
}
function add_module_permission($module_id,$role)
{
$res=$this->insert_table("role_permissions",array("role"=>$role,"module_id"=>$module_id));
return $res;
}
function add_submodule_permission($module_id,$role,$parent_id)
{
$res=$this->insert_table("submodules_permissions",array("role"=>$role,"module_id"=>$module_id,"parent_id"=>$parent_id));
return $res;
}
function debug_log($message)
{
$fp = fopen ("frontend/debug.log","a+");
$date = date("d-m-Y H:i:s");
$log = $date ."\t ".$message."\n";
fwrite($fp,$log);
fclose($fp);
///////////////////
if(file_exists("../frontend/debug.log"))
{
$fp3 = fopen ("../frontend/debug.log");
$date = date("d-m-Y H:i:s");
$log = $date ."\t ".$message."\n";
fwrite($fp3,$log);
fclose($fp3);
}
}
//////////////////////////////
function daily_report($dfrom,$dto)
{
#$query = "SELECT * from callregister where current_date >='$dfrom' and current_date <='$dto' ";
$query = "SELECT * from callregister where cdate >='$dfrom' and cdate <='$dto' ";
#echo $query;
$query=$this->db->query($query);
$res=$query->result();
return $res;
}
/////adeel function//////
///////////////////////////////////////////////////////////adeel////////////
function summary_rep($month,$year)
{
$query="SELECT cdate,COUNT(*) as total FROM callregister WHERE MONTH(cdate)='$month' AND YEAR(cdate)='$year' GROUP BY cdate ";
$query=$this->db->query($query);
$res=$query->result();
return $res;
}
/////////////call register pending tasks//////////////
function pending_report($dfrom,$dto)
{
#$query = "SELECT * from pending where current_date >='$dfrom' and current_date <='$dto' ";
$query = "SELECT * from pending where cdate >='$dfrom' and cdate <='$dto' ";
#echo $query;
$query=$this->db->query($query);
$res=$query->result();
return $res;
}
///////////////////////////////
}
?>
database.php
hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'callregister',
'dbdriver' => 'mysqli',

Error Code 1 when trying to insert video along with its details into mysql database in php

I am trying to make youtube clone website in php. I am stuck at a stage where i want to insert video that i am trying to upload into mysql database but it says error code 1. My project structure is as follows in below image
Screenshot of my website when i upload the entry as below
When click on upload button, i get the error as below image
Here is my upto date code that i have tried.
index.php File:
<?php require_once("includes/header.php"); ?>
<?php require_once("includes/footer.php"); ?>
header.php file:
<?php require_once("includes/config.php"); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>VideoTube</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="assets/css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src="assets/js/commonActions.js"></script>
</head>
<body>
<div id="pageContainer">
<!-- Master Head Container -->
<div id="mastHeadContainer">
<!-- Hamburger Menu Button -->
<button class="navShowHide">
<img src="assets/images/icons/menu.png">
</button> <!--End of Hamburger Menu Button -->
<!-- Site Logo -->
<a class="logoContainer" href="index.php">
<img src="assets/images/icons/VideoTubeLogo.png" title="logo" alt="Site logo">
</a> <!-- End of Site Logo -->
<!-- Search Bar -->
<div class="searchBarContainer">
<form action="search.php" method="GET">
<input type="text" class="searchBar" name="term" placeholder="Search...">
<button class="searchButton">
<img src="assets/images/icons/search.png">
</button>
</form>
</div> <!-- End of Search Bar -->
<!-- Right Icons Area -->
<div class="rightIcons">
<a href="upload.php">
<img class="upload" src="assets/images/icons/upload.png">
</a>
<a href="#">
<img class="upload" src="assets/images/profilePictures/default.png">
</a>
</div> <!-- End of Right Icons Area -->
</div> <!-- End of Master Head Container -->
<div id="sideNavContainer" style="display:none;">
</div>
<div id="mainSectionContainer">
<div id="mainContentContainer">
footer.php file:
</div>
</div>
</div>
</body>
</html>
config.php file:
<?php
ob_start(); // turns on output buffering
date_default_timezone_set("Asia/Calcutta");
try {
$con = new PDO("mysql:dbname=VideoTube;host=localhost", "root", "");
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
}catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>
VideoDetailsFormProvider.php file:
<?php
class VideoDetailsFormProvider {
private $con;
public function __construct($con) {
$this->con = $con;
}
public function createUploadForm() {
$fileInput = $this->createFileInput();
$titleInput = $this->createTitleInput();
$descriptionInput = $this->createDescriptionInput();
$privacyInput = $this->createPrivacyInput();
$categoriesInput = $this->createCategoriesInput();
$uploadButton = $this->createUploadButton();
return "<form action='processing.php' method='POST' enctype='multipart/form-data'>
$fileInput
$titleInput
$descriptionInput
$privacyInput
$categoriesInput
$uploadButton
</form>";
}
private function createFileInput() {
return "<div class='form-group'>
<input type='file' class='form-control-file' id='exampleFormControlFile1' name='fileInput' required>
</div>";
}
private function createTitleInput() {
return "<div class='form-group'>
<input class='form-control' type='text' placeholder='Title' name='titleInput'>
</div>";
}
private function createDescriptionInput() {
return "<div class='form-group'>
<textarea class='form-control' placeholder='Description' name='descriptionInput' rows='3'></textarea>
</div>";
}
private function createPrivacyInput() {
return "<div class='form-group'>
<select class='form-control' name='privacyInput'>
<option value='0'>Private</option>
<option value='1'>Public</option>
</select>
</div>";
}
private function createCategoriesInput() {
$query = $this->con->prepare("SELECT * FROM categories");
$query->execute();
$html = "<div class='form-group'>
<select class='form-control' name='categoryInput'>";
while($row = $query->fetch(PDO::FETCH_ASSOC)) {
$id = $row["id"];
$name = $row["name"];
$html .= "<option value='$id'>$name</option>";
}
$html .= "</select>
</div>";
return $html;
}
private function createUploadButton() {
return "<button type='submit' class='btn btn-primary' name='uploadButton'>Upload</button>";
}
}
?>
VideoProcessor.php file:
<?php
class VideoProcessor {
private $con;
private $sizeLimit = 500000000;
private $allowedTypes = array("mp4", "flv", "webm", "mkv", "vob", "ogv", "ogg", "avi", "wmv", "mov", "mpeg", "mpg");
public function __construct($con) {
$this->con = $con;
}
public function upload($videoUploadData) {
$targetDir = "uploads/videos/";
$videoData = $videoUploadData->videoDataArray;
$tempFilePath = $targetDir . uniqid() . basename($videoData["name"]);
//uploads/videos/5aa3e9343c9ffdogs_playing.flv
$tempFilePath = str_replace(" ", "_", $tempFilePath);
$isValidData = $this->processData($videoData, $tempFilePath);
if(!$isValidData) {
return false;
}
if(move_uploaded_file($videoData["tmp_name"], $tempFilePath)) {
$finalFilePath = $targetDir . uniqid() . ".mp4";
if(!$this->insertVideoData($videoUploadData, $finalFilePath)) {
echo "Insert query failed";
return false;
}
}
}
private function processData($videoData, $filePath) {
$videoType = pathInfo($filePath, PATHINFO_EXTENSION);
if(!$this->isValidSize($videoData)) {
echo "File too large. Can't be more than " . $this->sizeLimit . " bytes";
return false;
}
else if(!$this->isValidType($videoType)) {
echo "Invalid file type";
return false;
}
else if($this->hasError($videoData)) {
echo "Error code: " . $videoData["error"];
return false;
}
return true;
}
private function isValidSize($data) {
return $data["size"] <= $this->sizeLimit;
}
private function isValidType($type) {
$lowercased = strtolower($type);
return in_array($lowercased, $this->allowedTypes);
}
private function hasError($data) {
return $data["error"] != 0;
}
private function insertVideoData($uploadData, $filePath) {
$query = $this->con->prepare("INSERT INTO videos(title, uploadedBy, description, privacy, category, filePath)
VALUES(:title, :uploadedBy, :description, :privacy, :category, :filePath)");
$query->bindParam(":title", $uploadData->title);
$query->bindParam(":uploadedBy", $uploadData->uploadedBy);
$query->bindParam(":description", $uploadData->description);
$query->bindParam(":privacy", $uploadData->privacy);
$query->bindParam(":category", $uploadData->category);
$query->bindParam(":filePath", $filePath);
return $query->execute();
}
}
?>
VideoUploadData.php File:
<?php
class VideoUploadData {
public $videoDataArray, $title, $description, $privacy, $category, $uploadedBy;
public function __construct($videoDataArray, $title, $description, $privacy, $category, $uploadedBy) {
$this->videoDataArray = $videoDataArray;
$this->title = $title;
$this->description = $description;
$this->privacy = $privacy;
$this->category = $category;
$this->uploadedBy = $uploadedBy;
}
}
?>
processing.php File:
<?php
require_once("includes/header.php");
require_once("includes/classes/VideoUploadData.php");
require_once("includes/classes/VideoProcessor.php");
if(!isset($_POST["uploadButton"])) {
echo "No file sent to page.";
exit();
}
// 1) create file upload data
$videoUploadData = new VideoUploadData(
$_FILES["fileInput"],
$_POST["titleInput"],
$_POST["descriptionInput"],
$_POST["privacyInput"],
$_POST["categoryInput"],
"REPLACE-THIS"
);
// 2) Process video data (upload)
$videoProcessor = new VideoProcessor($con);
$wasSuccessful = $videoProcessor->upload($videoUploadData);
// 3) Check if upload was successful
?>
upload.php File:
<?php
require_once("includes/header.php");
require_once("includes/classes/VideoDetailsFormProvider.php");
?>
<div class="column">
<?php
$formProvider = new VideoDetailsFormProvider($con);
echo $formProvider->createUploadForm();
?>
</div>
<?php require_once("includes/footer.php"); ?>
Per https://www.php.net/manual/en/features.file-upload.errors.php:
UPLOAD_ERR_INI_SIZE
Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.
You should be able to increase upload_max_filesize in php.ini to resolve the issue.

Why isn't my php inputting the data? Am I missing something? [duplicate]

This question already exists:
How do I make my php not send form data to mysql if it doesn't meet criteria?
Closed 4 years ago.
As stated in the above title, I am completely perplexed as to why my site doesn't insert the data into my database (and yes I've made all the necessary columns and stuff). It is probably related to the radio buttons and the "Preke" tag so if you see anything I've messed up on, it'd help me out a lot!
Hese is my code:
<!DOCTYPE HTML>
<?php
// define variables and set to empty values
$VarErr = $PavErr = $AdErr = $PreErr = $PkErr = $KiekErr = "";
$Vardas = $Pavarde = $Adresas = $Preke = $Pk = $Kiekis = "";
?>
<html class="no-js" lang="en">
<head>
<title>Dailės parduotuvė</title>
<meta charset="UTF-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="css/stilius.css">
</head>
<body class="content ">
<div class="container">
<nav class="navbar navbar-expand-lg navbar-dark ">
<a class="navbar-brand" href="index.html">Kauno dailė</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="Visos.html">Visos prekės</a>
</li>
<li class="nav-item">
<a class="nav-link" href="Uzsakymas.php">Užsisakymas</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Kontaktai</a>
</li>
</ul>
</div>
</nav>
<div>
<div class="content sm-4 text-center">
<h2>Užsisakymo forma</h2>
<p><span class="error">* privalomi laukai</span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<p class="text-center">Vardas</p><br>
<input type="text" name="Vardas" value="<?php echo $Vardas;?>">
<span class="error">* <?php echo $VarErr;?></span>
<p class="text-center">Pavarde</p><br>
<input type="text" name="Pavarde" value="<?php echo $Pavarde;?>">
<span class="error">* <?php echo $PavErr;?></span>
<p class="text-center">Adresas</p><br>
<input type="text" name="Adresas" value="<?php echo $Adresas;?>">
<span class="error">* <?php echo $AdErr;?></span><br>
Prekės rūšis:<br>
<input type="radio" name="Preke" value="Vienišas(-a)" checked>Dažai(5€)<br>
<input type="radio" name="Preke" value="Susituokęs(-usi)">Teptukas(2€)<br>
<input type="radio" name="Preke" value="Išsiskyręs(-usi)">Pieštukas(2€)<br>
<input type="radio" name="Preke" value="Našlys(-ė)">Ofiso įrankis(1€)<br>
<span class="error">* <?php echo $PreErr;?></span>
<br>
<p class="text-center">Prekės kodas</p><br>
<input type="number" name="Pk" value="<?php echo $Pk;?>">
<span class="error">* <?php echo $PkErr;?></span>
<p class="text-center">Kiekis</p><br>
<input type="number" name="Kiekis" value="<?php echo $Kiekis;?>">
<span class="error">* <?php echo $KiekErr;?></span>
<br>
<!-- Input For Add Values To Database-->
<input type="submit" name="insert" value="Užsisakyti">
</div>
</div>
<div class="content py-5">
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["Vardas"])) {
$VarErr = "Įveskite vardą";
} else {
$Vardas= test_input($_POST["Vardas"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$Vardas)) {
$VarErr = "Galima vesti tik su raidėmis";
}
}
if (empty($_POST["Pavarde"])) {
$PavErr = "Įveskite pavardę";
} else {
$Pavarde = test_input($_POST["Pavarde"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$Pavarde)) {
$PavErr = "Galima vesti tik su raidėmis";
}
}
if (empty($_POST["Adresas"])) {
$AdErr = "Įveskite adresą";
} else {
$Adresas= test_input($_POST["Adresas"]);
}
}
if (empty($_POST["Preke"])) {
$PreErr = "Pasirinkite prekės tipą";
} else {
$Preke = test_input($_POST["Preke"]);
}
if (empty($_POST["Pk"])) {
$Pk = "Įveskite prekės kodą";
} else {
$Pk = test_input($_POST["Pk"]);
}
if (empty($_POST["Kiekis"])) {
$KiekErr = "Įveskite kiekį";
} else {
$Kiekis = test_input($_POST["Kiekis"]);
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$host = "localhost";
$user = "root";
$password ="";
$database = "uzsakymas";
try{
$connect = mysqli_connect($host,$user,$password,$database);
}
catch(mysqli_sql_exception $ex){
echo 'database connection error';
}
//insert
if(isset($_POST['insert'])) {
$Vardas = $_POST['Vardas'];
$Pavarde = $_POST['Pavarde'];
$Adresas = $_POST['Adresas'];
$Preke = $_POST['Preke'];
$Pk = $_POST['Pk'];
$Kiekis = $_POST['Kiekis'];
$insert_query = "INSERT INTO uzsakymai (Vardas,Pavarde,Adresas,Preke,Pk,Kiekis,)VALUES('$Vardas','$Pavarde','$Adresas','$Preke','$Pk','$Kiekis')";
try {
$insert_result = mysqli_query($connect,$insert_query);
if($insert_result){
if(mysqli_affected_rows($connect) > 0)
{
echo 'Data Inserted';
}else{
echo'Data not Inserted';
}
}
} catch(Exception $ex) {
echo 'Error Insert'.$ex->getMessmessage();
}
}
?>
</div>
<div class = "footer py-5 bg-secondary">
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
Your problem is in 'input value' properties. You set it to empty variables. Remove value from input tag like this:
<p class="text-center">Vardas</p><br><input type="text" name="Vardas" placeholder="Vardas">
it should work. About your MySQL queries, they are vulnerable for SQL Injections attack. Use PDO to protect against SQL Injections.
You have already inserted values and if you want to use values="". Then, in your SQL, you should UPDATE and not INSERT. Also,as rpm192 stated above you should use parameterized queries, otherwise you will face SQL injections. Good Luck!

Codeigniter project have different result beetween hostinger and localhost

I just upload my website from localhost to hostinger with filezilla.
I already configure the database setting and all working well, but i get different result if i want login to the website. it give error "the username or password is wrong".
After that, I run the website in my localhost. Login with same username/ password and its working.
I dont know the error, i use same code between the local and hostinger
controller/login.php
<?php
class Login extends CI_Controller {
function __construct() {
parent::__construct();
session_start();
$this->load->model(array('mlogin'));
if ($this->session->userdata('email')) {
$this->load->view('header1');
}
elseif (!$this->session->userdata('email')) {
$this->load->view('header');
}
}
function index() {
$this->load->view('login');
}
function proses() {
$this->form_validation->set_rules('email', 'email', 'required|trim|xss_clean');
$this->form_validation->set_rules('password', 'password', 'required|trim|xss_clean');
if ($this->form_validation->run() == FALSE) {
$this->load->view('login');
} else {
$usr = $this->input->post('email');
$psw = $this->input->post('password');
$u = mysql_real_escape_string($usr);
$p = md5(mysql_real_escape_string($psw));
$cek = $this->mlogin->cek($u, $p);
if ($cek->num_rows() > 0) {
//login berhasil, buat session
foreach ($cek->result() as $qad) {
$sess_data['u_id'] = $qad->u_id;
$sess_data['nama'] = $qad->nama;
$sess_data['email'] = $qad->email;
$sess_data['role'] = $qad->role;
$this->session->set_userdata($sess_data);
}
redirect('home');
} else {
$this->session->set_flashdata('result_login', '<br>Username atau Password yang anda masukkan salah.');
redirect('login');
}
}
}
function logout() {
$this->session->sess_destroy();
redirect('login');
}}
model/mlogin.php
<?php
class Mlogin extends CI_Model {
private $table = "user";
function cek($email, $password) {
$this->db->where("email", $email);
$this->db->where("u_paswd", $password);
return $this->db->get("user");
}
function semua() {
return $this->db->get("user");
}
function cekKode($kode) {
$this->db->where("email", $kode);
return $this->db->get("user");
}
function cekId($kode) {
$this->db->where("u_id", $kode);
return $this->db->get("user");
}
function getLoginData($usr, $psw) {
$u = mysql_real_escape_string($usr);
$p = md5(mysql_real_escape_string($psw));
$q_cek_login = $this->db->get_where('users', array('email' => $u, 'password' => $p));
if (count($q_cek_login->result()) > 0) {
foreach ($q_cek_login->result() as $qck) {
foreach ($q_cek_login->result() as $qad) {
$sess_data['logged_in'] = 'vera';
$sess_data['u_id'] = $qad->u_id;
$sess_data['email'] = $qad->email;
$sess_data['nama'] = $qad->nama;
$sess_data['group'] = $qad->group;
$sess_data['rid'] = $qad->rid;
$this->session->set_userdata($sess_data);
}
redirect('main');
}
} else {
$this->session->set_flashdata('result_login', '<br>Username atau Password yang anda masukkan salah.');
header('location:' . base_url() . 'login');
}
}
function update($id, $info) {
$this->db->where("u_id", $id);
$this->db->update("user", $info);
}
function simpan($info) {
$this->db->insert("user", $info);
}
function hapus($kode) {
$this->db->where("u_id", $kode);
$this->db->delete("user");
}
}
view/login.php
<html>
<head>
<meta charset="UTF-8">
<title>Log in</title>
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<!-- Font Awesome Icons -->
<link href="<?php echo base_url('assets/css/font-awesome.min.css'); ?>" rel="stylesheet">
<!-- Theme style -->
<link href="<?php echo base_url('assets/css/AdminLTE.min.css'); ?>" rel="stylesheet">
<!-- iCheck -->
<link href="<?php echo base_url('assets/js/plugins/iCheck/square/blue.css'); ?>" rel="stylesheet">
</head>
<body>
<body class="login-page">
<div class="login-box">
<div class="login-logo">
<div class="login-box-body">
<h2>Login</h2>
<form action="<?php echo site_url('login/proses'); ?>" method="post">
<?php
if (validation_errors() || $this->session->flashdata('result_login')) {
?>
<div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Warning!</strong>
<?php echo validation_errors(); ?>
<?php echo $this->session->flashdata('result_login'); ?>
</div>
<?php } ?>
<div class="form-group has-feedback">
<input type="email" name="email" class="form-control" placeholder="Username"/>
<span class="glyphicon glyphicon-user form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" name="password" class="form-control" placeholder="Password"/>
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div>
<button type="submit" class="btn btn-primary btn-block btn-flat">Masuk</button>
<br>
<h4>Daftar Anggota Baru</h4>
</div><!-- /.col -->
</div>
</form>
</div><!-- /.login-box-body -->
</div><!-- /.login-box -->
<!-- jQuery 2.1.3 -->
<script src="<?php echo base_url('assets/js/plugins/jQuery/jQuery-2.1.3.min.js'); ?>"></script>
<!-- Bootstrap 3.3.2 JS -->
<script src="<?php echo base_url('assets/js/bootstrap.min.js'); ?>"></script>
<!-- iCheck -->
<script src="<?php echo base_url('assets/js/plugins/iCheck/icheck.min.js'); ?>"></script>
<script>
$(function () {
$('input').iCheck({
checkboxClass: 'icheckbox_square-blue',
radioClass: 'iradio_square-blue',
increaseArea: '20%' // optional
});
});
</script>
<script>
$(function () {
$("#slider").responsiveSlides({
auto: true,
nav: true,
speed: 500,
namespace: "callbacks",
pager: true,
});
});
</script>
<!--footer-starts-->
<?php $this->load->view('footer') ?>
<!---->
</div>
</body>
</html>
localhost php version 5.6.11
hostinger php version 5.6.18
Hostinger sensitive with capitalization
change this code
$this->form_validation->set_rules('email', 'email', 'required|trim|xss_clean');
$this->form_validation->set_rules('password', 'password', 'required|trim|xss_clean');
with this
$this->form_validation->set_rules('email', 'Email', 'required|trim|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'required|trim|xss_clean');
and i think this code will give you 0 for $p
$p = md5(mysql_real_escape_string($psw));
just use this
$p = md5($psw);

Categories