[EDIT]just put the post data in a var and delete $scope.
$scope.deleteData = function(email) {
if(confirm("Are you sure you want to delete this record?")){
var email1= email; $http.post('<?php echo site_url("index.php/user/delete_user");?>', {'email':email1}).error(function(){ console.log("error"); });
}
}
whenever i press delete button nothing happens.
please check the code and please reply with the solution. network payload pass nothing {}.
view/user_view.php
<!DOCTYPE html >
<html lang="en" ng-app="userApp">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
<script type="text/javascript" src="<?php echo base_url('assets/jquery/jquery-3.1.1.min.js'); ?>"></script>
<script type="text/javascript" src="<?php echo base_url('assets/bootstrap/js/bootstrap.min.js'); ?>"></script>
<link href="<?php echo base_url('assets/bootstrap/css/bootstrap.min.css'); ?>">
<script type="text/javascript">
/*function userController($scope,$http) {
$scope.users = [];
$http.get('<?php echo site_url('index.php/user/user_list'); ?>').success(function($data){ $scope.users=$data; });
}*/
var app = angular.module('userApp', []);
app.controller('userController', function($scope, $http) {
//$scope.buttonName = "Add";
$scope.deleteData = function() {
/*$http.post("<?php echo base_url(); ?>index.php/User/delete_user/",{'id':$scope.id})
.success(function(data,status,headers,config){
$scope.message = "Deleted Successfully!";
});
*/
$http.post('<?php echo site_url('index.php/user/delete_user');?>',
{'email':$scope.email}).error(function(){
console.log("error");
})
}
$scope.displayUsers = function() {
$scope.users = [];
$http.get('<?php echo site_url("index.php/user/user_list"); ?>').success(function($data){ $scope.users=$data; });
}
$scope.insertData = function(){
$http.post('<?php echo site_url('index.php/user/insert_user');?>',
{
'name':$scope.name,
'gender':$scope.gender,
'email':$scope.email,
'address':$scope.address,
'phone':$scope.phone
}).error(function() {
console.log("Error");
});
}
});
</script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css">
<!-- HTML5 shim and Respond.js for 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/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body ng-controller="userController">
<!-- ng-app : which tells the Angular framework to parse data from this div -->
<div class="container" ng-init="displayUsers()">
<button class="btn" data-toggle="modal" data-target="#myModal">Add Users</button>
<div class="row">
<div class="col-lg-12 col-md-12">
<input type="search" class="form-control" ng-model="searchUser" placeholder="Live Search">
<table class="table table-bordered table-condensed table-responsive" ng-controller="userController">
<thead>
<tr>
<td>Select</td>
<td>Name</td>
<td>Gender</td>
<td>Email</td>
<td>Address</td>
<td>Phone Number</td>
<td>Action</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in users | filter:searchUser">
<td><input type="checkbox"></td>
<td class="hidden">{{user.id}}</td>
<td>{{user.name}}</td>
<td>{{user.gender}}</td>
<td>{{user.email}}</td>
<td>{{user.address}}</td>
<td>{{user.phone}}</td>
<td>
<button class="btn btn-primary">Edit</button>
<button class="btn" name="btnDelete" ng-click="deleteData(user.email)" value="delete">Delete</button></td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<div class="col-md-12">
<form class="form form-horizontal">
<div class="form-group hidden">
<label for="name">id</label>
<input type="hidden" class="form-control" ng-model="id" id="name">
</div>
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" ng-model="name" id="name">
</div>
<div class="form-group">
<label for="gender">Gender</label>
<input type="radio" id="gender" ng-model="gender" value="male">Male
<input type="radio" id="gender" ng-model="gender" value="female">Female
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="text" class="form-control" ng-model="email" id="email">
</div>
<div class="form-group">
<label for="address">Address</label>
<input type="text" class="form-control" ng-model="address" id="address">
</div>
<div class="form-group">
<label for="phone">Phone Number</label>
<input type="text" class="form-control" ng-model="phone" id="phone">
</div>
<button type="button" class="btn btn-primary" ng-click="insertData()" type="submit">Insert</button>
</form>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
controller/User.php
<?php
defined('BASEPATH') OR EXIT ('DIRECT ACCESS IS NOT ALLOWED');
class User extends CI_Controller{
public function index(){
$this->load->view('user_view');
}
public function user_list(){
$data = $this->user_model->get_user_list();
$this->output->set_content_type('application/json')->set_output(json_encode($data));
}
public function insert_user(){
//$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
$_POST = json_decode(file_get_contents('php://input'),true);
$data = $_POST;
$this->user_model->insert_user_data($data);
}
public function delete_user(){
$_POST = json_decode(file_get_contents('php://input'),true);
$email= $_POST['email'];
$this->user_model->delete_user_data($email);
}
}
?>
model/user_model.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User_model extends CI_Model{
protected $table_name;
public function __construct(){
parent::__construct();
$this->table_name = 'user';
}
public function get_user_list(){
return $this->db->from($this->table_name)->get()->result_array();
}
public function insert_user_data($data){
$this->db->insert($this->table_name, $data);
}
public function delete_user_data($email){
$this->db->where('email',$email);
$this->db->delete('user');
}
}
?>
Network after click on delete.
The thing you are doing a wrong here is, passing email as an argument in function, you are not utilizing it:
$scope.deleteData = function(email) {
$http.post('<?php echo site_url('index.php/user/delete_user');?>',
{'email':email}).error(function(){
console.log("error");
})
}
use double quotes inside single quotes
$http.post('<?php echo site_url("index.php/user/delete_user");?>',
{'email':$scope.email}).error(function(){
console.log("error");
})
Related
I need a help here when I click on the edit button on the image below i expect to see data populated on a form in a bootstrap modal window I am using jquery ajax method to populate the data in the form of
and the edit modal image
Here is code for the home page
<?php require_once("connect.php"); ?>
<?php require_once("fetch.php"); ?>
<?php require_once("select.php"); ?>
<?php require_once("process.php"); ?>
<!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">
<title>Home</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/style.css">
<!-- HTML5 shim and Respond.js for 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/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
<ul class="nav nav-pills">
<li>Home</li>
</ul>
<button type="button" class="btn btn-primary pull-right" data-toggle="modal" data-target="#myModal">Add</button>
<table class="table" id="table">
<tr>
<th>S/N</th>
<th>Name</th>
<th>Email</th>
<th>Description</th>
<th>Edit</th>
<th>View</th>
<th>Delete</th>
</tr>
<?php
$query = "SELECT * FROM contact";
$runQuery = mysqli_query($connect, $query);
if(!$runQuery){
die("Could not run select query ".mysqli_error($connect));
}
$sn = 1;
while($row = mysqli_fetch_assoc($runQuery)){ ?>
<tr>
<td><?php echo $sn++ ?></td>
<td><?php echo $row["name"] ?></td>
<td><?php echo $row["email"] ?></td>
<td><?php echo $row["description"] ?></td>
<td>
<button type="button" data-toggle="modal" data-target="#myModal" class="btn btn-warning btn-sm edit-data" id="<?php echo $row['userid'] ?>">Edit</button>
</td>
<td>
<button type="button" data-target="#viewModal" data-toggle="modal" class="btn btn-primary btn-sm view-data" id="<?php echo $row['userid'] ?>">View</button>
</td>
<td>
<button type="button" class="btn btn-danger btn-sm del-data" id="<?php echo $row['userid'] ?>">Danger</button>
</td>
</tr>
<?php } ?>
</table>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Add Data</h4>
</div>
<div class="modal-body">
<div id="success" class="alert alert-success"></div>
<form class="form" method="POST" id="insertData">
<div id="nameError" class="alert alert-danger"></div>
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" name="name" id="name">
</div>
<div id="emailError" class="alert alert-danger"></div>
<div class="form-group">
<label>Email</label>
<input type="text" class="form-control" name="email" id="email">
</div>
<input type="hidden" name="userid" id="contactUserId">
<div id="descriptionError" class="alert alert-danger"></div>
<div class="form-group">
<label>Description</label>
<textarea name="description" id="description" class="form-control"></textarea>
</div>
<input type="submit" class="btn btn-primary" value="Add" name="add" id="add">
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="viewModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">View Data</h4>
</div>
<div class="modal-body" id="contactDetail">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="js/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/myscript.js"></script>
</body>
</html>
This code is for entering and updating data in the database process.php
<?php
if(!empty($_POST)){
$name = $_POST["name"];
$email = $_POST["email"];
$description = $_POST["description"];
$userid = $_POST["userid"];
if($userid != ''){
$query = "UPDATE contact SET name = '$name', email='$email', description='$description' WHERE userid = $userid ";
$runQuery = mysqli_query($connect, $query);
if(!$runQuery){
die("Could not run query ".mysqli_error($connect));
}
}else{
$query = "INSERT INTO contact(name, email, description) VALUES ";
$query .=" ('$name', '$email', '$description')";
$runQuery = mysqli_query($connect, $query);
if(!$runQuery){
die("Could not run insert query ".mysqli_error($connect));
}
}
}
This code retrieves data from database
<?php
if(isset($_POST['userid'])){
$editId = (int)$_POST['userid'];
$query = "SELECT * FROM contact WHERE userid = $editId";
$runQuery = mysqli_query($connect, $query);
if(!$runQuery){
die("Could not run query ".mysqli_error($connect));
}
$getData = mysqli_fetch_assoc($runQuery);
echo json_encode($getData);
}
This is my js file
$(document).ready(function(){
$("#insertData").submit(function(event){
event.preventDefault();
if($("#name").val() == ""){
$("#nameError").css("display", "block").html("Name is required");
}else if ($("#email").val() == "") {
$("#emailError").css("display", "block").html("Email is required");
}else if ($("#description").val() == "") {
$("#descriptionError").css("display", "block").html("Description is required");
}else{
$.ajax({
url: "index.php",
method: "POST",
data: $("#insertData").serialize(),
success: function(data){
$("#success").css("display", "block").html("Data added");
$("#insertData")[0].reset();
}
});
}
});
$(document).on("click", ".edit-data", function(){
var contactId = $(this).attr("id");
$.ajax({
url:"index.php",
method: "POST",
data: {contactId:contactId},
dataType: "json",
success: function(data){
$("#name").val(data.name);
$("#email").val(data.email);
$("#description").val(data.description);
$("#contactUserId").val(data.userid);
$("#add").val("Update");
$("#myModal").modal("show");
}
});
});
$(document).on('click', '.view-data', function(){
var contactId = $(this).attr("id");
if(contactId != '')
{
$.ajax({
url:"index.php",
method:"POST",
data:{contactId:contactId},
success:function(data){
$('#contactDetail').html(data);
$('#viewModal').modal('show');
}
});
}
});
});
You are sending contactId and in your PHP you are looking for userid. Change your data to data: { userid: userid }.
$(document).on("click", ".edit-data", function() {
var userid = $(this).attr("id");
$.ajax({
url: "index.php",
method: "POST",
data: { userid: userid },
dataType: "json",
success: function(data) {
$("#name").val(data.name);
$("#email").val(data.email);
$("#description").val(data.description);
$("#contactUserId").val(data.userid);
$("#add").val("Update");
$("#myModal").modal("show");
}
});
});
I've been really struggling with this today. Can't seem to get it to work, all it does is navigates to 'add-entry.php?go' in the navbar, but goes grey then reloads the index.php with modal still intact with my entries in it.
Here's my html, including the form and javascript filter input.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ProSys Component Lookup</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> <!--Custom CSS -->
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<!-- Wrapper -->
<div class="container-fluid">
<div class="col-xs-12">
<div class="col-xs-12">
<!-- Header -->
<div class="page-header">
<h1>ProSys Component Lookup</h1><br>
</div>
<!-- Main table content -->
<div class="container-fluid">
<button type="button" class="btn btn-primary btn-block" data-toggle="modal" data-target="#myModal">Add New Item</button><br>
<div class="modal fade" role="dialog" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Add New Item</h4>
</div>
<div class="modal-body">
<form method="post" action="add-entry.php?go" role="form">
<div class="form-group">
<label for="location">Location:</label>
<input type="text" class="form-control" name="location">
</div>
<div class="form-group">
<label for="category">Category:</label>
<select class="form-control" name="category">
<option>Processor</option>
<option>Diode</option>
<option>Fuse</option>
<option>Regulator</option>
<option>Capacitor</option>
<option>Inductor</option>
<option>LED</option>
<option>Gate</option>
<option>Modem</option>
<option>Transceiver</option>
<option>Thermistor</option>
<option>Load Switch</option>
<option>Op Amp</option>
<option>Optocoupler</option>
<option>Line Driver</option>
<option>ESD Protection</option>
<option>ADC</option>
<option>RTC</option>
</select>
</div>
<div class="form-group">
<label for="manufacturer">Manufacturer:</label>
<input type="text" class="form-control" name="manufacturer">
</div>
<div class="form-group">
<label for="description">Description:</label>
<textarea type="text" class="form-control" name="description" rows="5"></textarea>
</div>
<div class="form-group">
<label for="packagesize">PackageSize:</label>
<input type="text" class="form-control" name="packagesize">
</div>
<div class="form-group">
<label for="category">Supplier:</label>
<select class="form-control" name="supplier">
<option>Farnell</option>
<option>RS</option>
<option>Rapid</option>
</select>
</div>
<div class="form-group">
<label for="suppliernumber">Supplier Number:</label>
<input type="text" class="form-control" name="suppliernumber">
</div>
<div class="form-group">
<label for="stock">Stock:</label>
<input type="text" class="form-control" name="stock">
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-default">Add</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- Search box -->
<div class="col-md-3">
<form class="styled">
<input type="text" class="form-control" onkeyup="myFunctionOne()" id="myInput" placeholder="Search..">
</form><br>
</div>
<div class="panel">
<div class="panel-body">
<div class="row">
<div class="col-xs-12">
<table class="table table-hover" id="table_demo">
<thead>
<tr>
<th>Location</th>
<th>Manufacturer</th>
<th>Description</th>
<th>PackageSize</th>
<th>Supplier</th>
<th>SupplierNumber</th>
<th>Stock</th>
</tr>
</thead>
<tbody id="myTable">
<tr>
<!-- Database connect and display as table -->
<?php
include("dbconnect.php");
$result = mysql_query("SELECT DrawLocation, Manufacturer, Description, PackageSize, Supplier, SupplierNumber, Stock FROM complibrary");
while($complibrary = mysql_fetch_array($result))
{
echo"<td>".$complibrary['DrawLocation']."</td>";
echo"<td>".$complibrary['Manufacturer']."</td>";
echo"<td>".$complibrary['Description']."</td>";
echo"<td>".$complibrary['PackageSize']."</td>";
echo"<td>".$complibrary['Supplier']."</a></td>";
//IF statement adds in links for web search via SupplierNumber
if ($complibrary['Supplier'] == 'Farnell') {
echo"<td><a target='_blank' href='http://uk.farnell.com/search?st=".$complibrary['SupplierNumber']."'>".$complibrary['SupplierNumber']."</a></td>";
} elseif ($complibrary['Supplier'] == 'RS') {
echo"<td><a target='_blank' href='http://uk.rs-online.com/web/c/?sra=oss&r=t&searchTerm=".$complibrary['SupplierNumber']."'>".$complibrary['SupplierNumber']."</a></td>";
} elseif ($complibrary['Supplier'] == 'Rapid') {
echo"<td><a target='_blank' href='https://www.rapidonline.com/Catalogue/Search?query=".$complibrary['SupplierNumber']."'>".$complibrary['SupplierNumber']."</a></td>";
} else {
echo"<td>".$complibrary['SupplierNumber']."</td>";
}
//IF statement end
echo"<td>".$complibrary['Stock']."</td>";
echo "</tr>";
}
mysql_close($conn);
?>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<!-- Latest jQuery -->
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<!-- Filtering script -->
<script>
function myFunctionOne() {
var input, filter, table, tr, td, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[2];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
</html>
And here's my add-entry.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<?php
if (isset($_POST['location'])){
$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "componentlookup";
$conn = mysql_connect($hostname, $username, $password);
if (!$conn) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname, $conn);
$location = $_POST['location'];
$category = $_POST['category'];
$manufacturer = $_POST['manufacturer'];
$description = $_POST['description'];
$packagesize = $_POST['packagesize'];
$supplier = $_POST['supplier'];
$suppliernumber = $_POST['suppliernumber'];
$stock = $_POST['stock'];
$query = mysql_query("INSERT INTO 'complibrary' (ID, DrawLocation, Category, Manufacturer, Description, PackageSize, Supplier, SupplierNumber, Stock) VALUES ('NULL', '$location', '$category', '$manufacturer', '$description', '$packagesize', '$supplier', '$suppliernumber', '$stock')");
echo "Item added sucessfully. Click <a href='index.php'>HERE</a> to go back.";
mysql_close($conn);
}
?>
</body>
</html>
Any ideas?
I think you should put data-dismiss="modal" on the add button to close the window.
Also, I think you should not use mysql connection. Better, use mysqli or PDO.
On registration, password is getting saved as intended encrypted but while login, it is throwing a message that password is not matching, because encrypted password is not decrypting while login. Can any one help me out with this ? I want to login successfully with encrypted password.
Here is my controller
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use Illuminate\Http\Request;
use DB;
use Session;
use Redirect;
use App\User;
use App\Http\Requests\UserRequest as UserRequest;
// use App\Http\Requests\CreateArticleRequest as CreateArticleRequest;
use App\Http\Controllers\Controller;
use Illuminate\View\Middleware\ErrorBinder;
use Illuminate\Support\Facades\Input;
use Hash;
use Crypt;
use Bcrypt;
class ctrl extends Controller
{
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('auth');
}
public function registration_function(Request $request)
{
$nam_value = $request->nam;
$email_value = $request->r_email;
$password_value = $request->r_password;
$city_value = $request->city;
$login_email = $request->l_email;
$login_password = $request->l_password;
$bcrypt = new Bcrypt(15);
$password_value = $bcrypt->hash($password_value);
$login_password = $bcrypt->verify($password_value, $login_password);
// $password_value = Crypt::encrypt($password_value);
// $login_password = Crypt::encrypt($password_value);
if($email_value)
{
$valid_user = DB::table('registered')
->where('email',$email_value)
->get();
if($valid_user)
{
return redirect('makelogin_page')->with('status_validate','You are already registered with us, Plaese login, Did you forgot your password ?');
}
else
{
$reg=DB::table('registered')->insert(['name' => $nam_value, 'email' => $email_value, 'password'=>$password_value,'city'=>$city_value]);
return redirect('makelogin_page')->with('status','Registered Successfully');
}
}
else
{
$log_display = DB::table('registered')
->where('email',$login_email)
->where('password',$login_password)
->get();
if($log_display)
{
return redirect('dodofront');
}
else
{
return redirect('makelogin_page')->with('status','Please enter the valid credentials, Did you forgot your password ?');
}
}
}
}
Here is my blade.php page
<!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">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Dashboard | Design Dodo</title>
<!-- Bootstrap -->
<link href="main.css" rel="stylesheet"/>
<script src="bootstrap/jquery.min.js"></script>
<script src="bootstrap/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
</head>
<body>
<br/>
<div class="container">
<h3>New user ?</h3>
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#registration">Register</button>
<!-- Modal -->
<div class="modal fade" id="registration" role="dialog">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Registration</h4>
</div>
<div class="modal-body">
<p>Please Register Yourself Here</p>
<form role="form" action="registration_page" method="get">
<div class="form-group">
<input type="text" class="form-control" name="nam" placeholder="Your Name Please" style="width:265px;" required/>
</div>
<div class="form-group">
<input type="email" class="form-control" name="r_email" placeholder="Your Email Please" style="width:265px;" required/>
</div>
<div class="form-group">
<input type="password" class="form-control" name="r_password" placeholder="Please enter a password" style="width:265px;" required/>
</div>
<div class="form-group">
<input type="text" class="form-control" name="city" placeholder="Please enter your city" style="width:265px;" required/>
</div>
<div class="form-group">
<input type="submit" class="btn btn-info" value="Register">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<h3>Existing user ?</h3>
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#login">Login</button>
<!-- Modal -->
<div class="modal fade" id="login" role="dialog">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Login</h4>
</div>
<div class="modal-body">
<p>Please Login Here</p>
<form role="form" action="login_page" method="get">
<div class="form-group">
<input type="email" class="form-control" name="l_email" placeholder="Your Email Please" style="width:265px;" required/>
</div>
<div class="form-group">
<input type="password" class="form-control" name="l_password" placeholder="Please enter a password" style="width:265px;" required/>
</div>
<div>
<input type="submit" class="btn btn-info" value="login">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</body>
And here is route
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
return view('welcome');
});
Route::auth();
Route::get('/registration_page','ctrl#registration_function');
Route::get('/login_page','ctrl#registration_function');
THis code is throwing an error which is
FatalErrorException in ctrl.php line 40:
Class 'Bcrypt' not found
Please help me to solve this issue
I have a form that makes a calculation, enter the database and returns the value through an alert.
I would like to replace this alert for modal.
HTML
<form method="post" action="#">
<input type="text" name="alt" id="altura" required><br><br>
<input type="text" name="peso" id="peso" required><br><br>
<button type="submit" id="Send">Send</button>
</form>
PHP
function calcularIMC($altura,$peso){
$imc = 0;
if($altura >0 && $peso >0){
$imc = $peso / ($altura * $altura);
}
echo '<script>';
echo 'alert("'.$imc.'");';
echo '</script>';
}
I tried as follows:
- Added the php after the tag </html> code;
- Added the variable responsible for the calculation: $imc;
- I linked the button Send with modal.
<form method="post" action="#">
<input type="hidden" name="acao" id="acao" value="cadastrar"/>
<input type="text" name="alt" id="altura" required><br><br>
<input type="text" name="peso" id="peso" required><br><br>
<button type="submit" id="Enviar" data-toggle="modal" data-target="#myModal">Enviar</button>
</form>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<?php echo'.$imc.';?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</body>
</html>
PHP
<?php
function calcularIMC($altura,$peso){
$imc = 0;
if($altura >0 && $peso >0){
$imc = $peso / ($altura * $altura);
}
return $imc;
}
?>
Thus, when I click on Send button (with all the empty fields), it opens the modal and displays the '.$imc.' as String.
When I insert the data and click on the button Send a dims window (early effect of modal) and quickly back to normal. I believe the modal is being called, but some stretch it gives erros and closes.
How can I solve this?
AJAX, top of code:
<?php
$imc = false;
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$imc = calcularImc($_POST['altura'], $_POST['peso']);
}
?>
End of body
<?php
if ($imc !== false){
echo "<script>$('#myModal').modal('show');</script>";
}
?>
Would it be this? I tried to add this code, but gave the same result. By submitting the form, the window dims and quickly back to normal.
---------------------------------UPDATED / I MANAGED TO DO THAT I WANTED-------------------------------
<form method="post" action="#">
<input type="text" name="alt" id="altura" required><br><br>
<input type="text" name="peso" id="peso" required><br><br>
<button type="submit" id="Send" data-toggle="modal" data-target="#myModal">Send</button>
</form>
<?php
$imc = false;
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$imc = calcularImc($_POST['altura'], $_POST['peso']);
}
?>
<?php
if ($imc !== false){
echo '<script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>';
echo '<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>';
echo "<script>$('#myModal').modal('show');</script>";
}
?>
</body>
</html>
function calcularIMC($altura,$peso){
$imc = 0;
if($altura >0 && $peso >0){
$imc = $peso / ($altura * $altura);
}
echo '<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">';
echo $imc; // RESULT OF CALC MODAL INSIDE
echo '</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>';
}
?>
POST Method:
<?php
function calcularIMC($altura,$peso){
$imc = 0;
if($altura >0 && $peso >0){
$imc = $peso / ($altura * $altura);
}
return $imc;
}
$imc = "";
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$imc = calcularImc($_POST['alt'], $_POST['peso']);
?>
<script type="text/javascript">
$(window).load(function(){
$('#myModal').modal('show');
});
</script>
<?php
}
?>
<form method="post" action="#">
<input type="hidden" name="acao" id="acao" value="cadastrar"/>
<input type="text" name="alt" id="altura" required><br><br>
<input type="text" name="peso" id="peso" required><br><br>
<button type="submit" id="Send">Send</button>
</form>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<?php echo $imc;?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</body>
</html>
Errors you made:
Addres altura as $_POST['altura'] instead of $_POST['alt'] (as its name attribute is alt)
You started your modal.show script before the page was loaded. So the modal might not exist yet. Wrap it in $(window).load(function(){})
Printed the variable in the wrong way: echo'.$imc.' should have been echo $imc;
Even nicer would be to use AJAX. Then you don't have to refresh the page. If you want to do that, lookup AJAX. You could also avoid using PHP. #AceWebDesign Answer explains nicely how this can be done without PHP.
You could use jQuery for this.
instead of
echo '<script>';
echo 'alert("'.$imc.'");';
echo '</script>';
You could use this on the page. It may need some tweaking as it was quick and rough, and the modal was a little rusty.
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<form method="post" action="#">
<input type="hidden" name="acao" id="acao" value="cadastrar"/>
<input type="text" name="alt" id="altura" required><br><br>
<input type="text" name="peso" id="peso" required><br><br>
<button type="submit" id="Enviar" data-toggle="modal" data-target="#myModal">Enviar</button>
</form>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$(document).off("click", ".btn-default").on( "click", ".btn-default", function(e) {
var altura = $('#altura').val();
var peso = $('#peso').val();
var imc =0;
if (altura > 0 )
{
var imc = peso / (altura * altura);
}
$(".modal-body").html(imc);
$('#myModal').modal('show');
});
return false;
});
</script>
</body>
</html>
I am a newbie in Codeigniter. I cannot insert data into my table. I have used bootstrap files too.
These are lines from View - groups.php
<input type="text" name="group" id="group" placeholder="Group">
<button type="button" name="addgroup" class="btn btn-primary" id="add" data-dismiss="modal">Add</button>
Model - groups_model.php
function insert_groups($dbdata) {
$this->db->insert('groups', $dbdata);
}
Controller - groups_controller.php
public function group()
{
$this->load->view('groups');
$this->load->model('groups_model');
if(isset($_POST['addgroup']))
{
$userID= '2';
$groupname= $this->input->post('group');
//$this->load->model('groups_model');
$data=array(
'userID'=>$userID,
'groupname'=>$groupname
);
$this->groups_model->insert_groups($data);
//var_dump($this->db->last_query());
}
}
}
My full html form is pasted below. There are a lot of comments in there.
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>Content</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="<?php echo base_url(); ?>stylesheets/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="<?php echo base_url(); ?>stylesheets/bootstrap.css" rel="stylesheet" type="text/css">
<link href="<?php echo base_url(); ?>stylesheets/bootstrap-theme.min.css" rel="stylesheet" type="text/css">
<link href="<?php echo base_url(); ?>stylesheets/bootstrap-theme.css" rel="stylesheet" type="text/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.3.0/respond.min.js"></script>
<![endif]-->
<SCRIPT language="javascript">
// var person;
// var element;
//
// function add() {
// var e1 = document.getElementById('group').value;
// var e2 = document.getElementById('select');
// var o = document.createElement('option');
// o.value = "group_body.html";
// o.text = e1;
// e2.options.add(o);
//
// }
// function goto() {
// var index = document.getElementById('select').selectedIndex;
// if (index.value != "select") {
// location = index.value;
// }
// }
// function add()
// {
// //Create an input type dynamically.
// element = document.createElement("button");
// element.className='btn btn-default';
// var person = document.getElementById('group').value;
// var t = document.createTextNode(person);
// element.appendChild(t);
// element.id=person;
// //Assign different attributes to the element.
//// element.type = type;
//// element.value = type; // Really? You want the default value to be the type string?
//// element.name = type; // And the name too?
//
// element.onclick = function() { // Note this is a function
// //alert(element.id);
//// $(document).ready(function(){
//// $("#element").click(function(){
// $('body').load('group_body.html');
//// });
//// });
// };
//
// var foo = document.getElementById("fooBar");
// //Append the element in page (in span).
// foo.appendChild(element);
//// var d = document.getElementById('fooBar');
//// d.appendChild(i);
// }
//
// function copy()
// {
// var n1 = document.getElementById('addKeyword');
// var n2 = document.getElementById('getKeyword');
// n2.innerText = n1.value;
// }
</SCRIPT>
</head>
<body>
<form method="post" name="form1">
<div class="btn-group" id="fooBar">
<!-- <button type="button" class="btn btn-default">Marketing</button>
<button type="button" class="btn btn-default">Internet</button>
<button type="button" class="btn btn-default">Politics</button>-->
select a group:
<select class="form-control" id="select" onchange="javascript:location.href = this.value;">
<option selected value="select">select</option>
<!-- <option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>-->
</select>
<button type="button" class="btn btn-default" id="btnAdd" data-toggle="modal" data-target="#myModal">Add Group</button>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Group Name</h4>
</div>
<div class="modal-body">
<h5>Please enter Group Name:</h5>
<input type="text" name="group" id="group" placeholder="Group">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" name="addgroup" class="btn btn-primary" id="add" data-dismiss="modal">Add</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<div class="boxed">
<h4>Group:<span class="label label-default" id="span"><script>document.getElementById('group').innerText = document.getElementById('span').innerText</script></span>
<button type="submit" class="btn btn-default">Edit Name</button>
<button type="submit" class="btn btn-default">Disable</button>
<button type="submit" class="btn btn-default">Delete Group</button></h4>
<div class="row">
<div class="col-lg-6">
<div class="input-group">
<input type="text" class="form-control" placeholder="Enter your keyword" id="addKeyword">
<span class="input-group-btn">
<button class="btn btn-default" type="button" onclick="copy()">Add</button>
</span>
</div><!-- /input-group -->
</div><!-- /.col-lg-6 -->
</div>
<h4>Keywords:</h4>
<!-- <div class="keyword" id="getKeyword"></div>-->
</div>
</form>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://code.jquery.com/jquery.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="<?php echo base_url(); ?>javascripts/bootstrap.min.js"></script>
<script src="<?php echo base_url(); ?>javascripts/bootstrap.js"></script>
</body>
</html>
try
public function group()
{
$this->load->model('groups_model');
if($this->input->post('addgroup'))
{
$userID= '2';
$groupname= $this->input->post('group');
$data=array(
'userID'=>$userID,
'groupname'=>$groupname
);
$this->groups_model->insert_groups($data);
}
$this->load->view('groups');
}
}
And add action to your form :
Change
<form method="post" name="form1">
To
<?= form_open('yourcontroller/action')?>
//anything HTML inside your form
<?= form_close()?>
And you must load form helper to do this. In autoload.php
$autoload['helper'] = array('form');
Hope it helps !
Why are you using button when it should be submit.
change this
<button type="button" name="addgroup" class="btn btn-primary" id="add" data-dismiss="modal">Add</button>
to
<button type="submit" name="addgroup" class="btn btn-primary" id="add" data-dismiss="modal">Add</button>
You have to submit the data, to get it in post
Basically you don't have action attribute in your form tag.
<form method="post" name="form1">
You can use this expressions:
<form action="yourcontroller/action" method="post" name="form1">
or use the Codeigniter form helper
$this->load->helper('form');
echo form_open("yourcontroller/action");
Hope it helps you.