hello i’m using a stack overflow and i want to implement the login modal in my POS method so my plan here is that whenever i click the VOID button there was a login modal that will pop up to validate if the user has the authority to void a product
code under edit.php
Void Products
<div id="loginModal" 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">Login</h4>
</div>
<div class="modal-body">
<label>Username</label>
<input type="text" name="username" id="username" class="form-control" />
<br />
<label>Password</label>
<input type="password" name="password" id="password" class="form-control" />
<br />
<button type="button" name="login_button" id="login_button" class="btn btn-warning">Login</button>
</div>
</div>
</div>
</div>
and yeah it’s working as i expected and here is my ajax under edit.php
$(document).ready(function() {
$('#login_button').click(function(){
var username = $('#username').val();
var password = $('#password').val();
if(username != '' && password != '')
{
$.ajax({
url:"action.php",
method:"POST",
data: {username:username, password:password},
success:function(data)
{
//alert(data);
if(data == 'No')
{
alert("Wrong Data");
}
else
{
$('#loginModal').hide();
location.reload();
}
}
});
}
else {
alert("Both fields are required");
}
});
});
and my problem is that i’m using a code igniter framework and i do not know how to implement this line of code into my program
action.php
<?php
session_start();
$connect = mysqli_connect("localhost", "root", "", "bubblebee");
if(isset($_POST["username"]))
{
$query = "
SELECT * FROM admin_login
WHERE admin_name = '".$_POST["username"]."'
AND admin_password = '".$_POST["password"]."'
";
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
$_SESSION['username'] = $_POST['username'];
echo 'Yes';
}
else
{
echo 'No';
}
}
if(isset($_POST["action"]))
{
unset($_SESSION["username"]);
}
?>
when press the both required filed is working but the username and password seems like have a problem and i can’t identify what is my error here maybe i do not know how to implement it in the code igniter? can someone teach me.
my folder structure right now with that action.php is something like this
- application
- view
- order
- action.php
- create.php
- edit.php
- index.php
- order
- view
2
Answers
code under
edit.php
Void ProductsModel Code:-
Controller Code:-
you can add form in modal
and create function to catch the request on controller