Keep me logged in php function using modal dialog login form - javascript

I want to do is when I check the checkbox button in my dialog box the email and the password that I've typed on it will be saved and redirect to profile.php.
My problem is it doesn't work and I have an error in the inputbox that says:
Undefined index: unm and Undefined index: pwd
Does anyone here can help me with my problem?
PHP:
<?php
if(isset($_POST['login'])) {
if(isset($_POST['chkbox'])) {
setcookie("unm",$_POST['email'],time()+3600);
setcookie("pwd",$_POST['password'],time()+3600);
}
?>
<script type="text/javascript">
window.location="profile.php";
</script>
<?php
}
?>
HTML:
<a data-toggle="modal" href="#myModal"><span class="glyphicon glyphicon-user"></span> Login</a>
<div class="container">
<div class="row">
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" 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>
<h5 class="modal-title">PLEASE ENTER YOUR EMAIL ADDRESS AND PASSWORD TO LOG IN.</h5>
</div>
<div class="modal-body">
<form class="form-horizontal">
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email</label>
<div class="col-md-9">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envelope-o fa-fw"></i></span>
<input type="text" name="email" value="<?php echo $_COOKIE['unm'] ?>" class="form-control" placeholder="Enter Email Address..." />
</div>
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-2 control-label">Password</label>
<div class="col-md-9">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-key fa-fw"></i></span>
<input type="password" name="password" value="<?php echo $_COOKIE['pwd'] ?>" class="form-control" placeholder="Enter Password..." />
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="checkbox" name="chkbox" value="staylogged" class="checkbox-inline" />
<label> Keep me logged in</label> <b>|</b>
Forgot your password?
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" name="login" class="btn btn-primary"><span class="glyphicon glyphicon-user"></span> Login</button>
<button type="button" id="show_signup_md" class="btn btn-info" data-dismiss="modal" aria-hidden="true"><span class="glyphicon glyphicon-list-alt"></span> Register</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>

First check if $_COOKIE['pwd'] or $_COOKIE['unm'] set at the html before echo them:
if(isset($_COOKIE['pwd']) && !empty($_COOKIE['pwd'])){
$pwd = $_COOKIE['pwd'];
}else{
$pwd = '';
}
//same for unm
if(isset($_COOKIE['unm']) && !empty($_COOKIE['unm'])){
$unm = $_COOKIE['unm'];
}else{
$unm = '';
}
then the input should be :
<input type="text" name="email" value="<?php echo $unm ?>" class="form-control" placeholder="Enter Email Address..." />
//same for pass
<input type="password" name="password" value="<?php echo $pwd ?>" class="form-control" placeholder="Enter Password..." />
Next thing don't store user details at cookies! . if do so use hashed string.

Related

Admin login panel page keep refreshing

i have a problem when i want to login into my admin login panel i use username and password and the page refresh and stays the same without going to Settings.php path that i want to go in . if i can even try to add another script can give me permission to access that Settings.php file witout having to go trought that login.php file that causes the problem
*first code : Login.php file
*Second code : Settings.php file
<br/><br/><br/>
<div class="col-md-4"></div>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">
<h4><i class="fa fa-lock"></i> login</h4>
</div>
<div class="panel-body">
<?php echo form_open('/auth/login');?>
<input type="text" placeholder="username" class="form-control " name="_name" />
<br/>
<input type="password" placeholder="password" class="form-control " name="_pass" />
<br/>
<input type="submit" name="login" class="btn btn-success" value="login" />
<?php echo form_close();?>
</div>
</div>
</div>
<div class="col-md-4"></div>
------------------------------------------------------------------------------
------------------------------------------------------------------------------
<div class="col-md-3"></div>
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<h4><i class="fa fa fa-gear"></i> General Settings </h4>
</div>
<!--<form method="post" action="{site_url}/dashboard/save_settings" >-->
<?php echo form_open('/dashboard/save_settings');?>
<div class="panel-body">
<div class="form-group">
<label for="site_name">Site Name</label>
<input name="site_name" class="form-control" id="site_name" value="{site_name}" type="text">
</div>
<div class="form-group">
<label for="site_mail">Email</label>
<input name="site_mail" class="form-control" id="site_mail" value="{site_mail}" type="text">
</div>
<div class="form-group">
<label for="site_desc">SEO description</label>
<textarea name="site_desc" class="form-control" id="site_desc" rows="3">{site_desc}</textarea>
</div>
<div class="form-group">
<label for="site_keys">SEO Keywords</label>
<textarea name="site_keys" class="form-control" id="site_keys" rows="3">{site_keys}</textarea>
</div>
<div class="form-group">
<label for="ad_code">Ad Code <small>(add ad code here like google adsense code or html code.)</small> </label>
<textarea name="ad_code" class="form-control" id="ad_code" rows="3">{ad}</textarea>
</div>
<!-- Social Media -->
<h5><b>Social Media</b></h5>
<div class="input-group">
<span class="input-group-addon" id="facebook"><i class="fa fa-facebook"></i></span>
<input name="facebook" type="text" value="{facebook}" class="form-control" aria-describedby="facebook">
</div>
<br/>
<div class="input-group">
<span class="input-group-addon" id="twitter"><i class="fa fa-twitter"></i></span>
<input name="twitter" type="text" value="{twitter}" class="form-control" aria-describedby="twitter">
</div>
<br/>
<div class="input-group">
<span class="input-group-addon" id="googleplus"><i class="fa fa-google-plus"></i></span>
<input name="googleplus" type="text" value="{googlep}" class="form-control" aria-describedby="googleplus">
</div>
<!-- END / Social Media -->
</div>
<div class="panel-footer">
<!--<input class="btn btn-success" type="submit" name="update" value="save" />-->
<button class="btn btn-success" type="submit" name="update"><i class="fa fa-save"></i> save</button>
</div>
<!--</form>-->
<?php echo form_close();?>
</div>
</div>
<div class="col-md-3"></div>

bootstrap 4 modal not showing

This is my page I am working on Bootstrap 4 modal, actually i want to get form values in the bootstrap 4 modal but its not showing, can someone check my code i don't know why its not responding ?
when i click on edit button it do nothing. I am using Mysql, Php, Bootstrap and Javascript.
Here is my code
$(document).ready(function(){
$(document).on('click','.edit_data', function(){
var project_id=$(this).attr("id");
$.ajax({
URL:"adminhome.php",
method:"POST",
data:{projectID:project_id},
dataType:"json",
success:function(data){
$('#pt').val(data.pt);
$('#s1_id').val(data.s1_id);
$('#s1_name').val(data.s1_name);
$('#s2_id').val(data.s2_id);
$('#s2_name').val(data.s2_name);
$('#s3_id').val(data.s3_id);
$('#s3_name').val(data.s3_name);
$('#project_id').val(data.id);
$('#update_user_modal').modal('show');
}
});
});
});
<a class="btn btn-warning btn-sm mt-1 text-white edit_data" role="button" name="edit" id="<?php echo $row[0]; ?>" >
<span class="">EDIT</span>
</a>
<!-- Modal - Update User details -->
<div class="modal fade" id="update_user_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" 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">Update</h4>
</div>
<div class="modal-body">
<form method="post" id="insert_form">
<div class="form-group">
<label for="update_title">Project Title</label>
<input type="text" id="pt" name="pt" placeholder="Project Title" class="form-control"/>
</div>
<div class="form-group">
<label for="update_student_id1">Student ID 1</label>
<input type="text" id="update_student_id1" id="s1_id" name="s1_id" placeholder="Student ID" class="form-control"/>
<label for="update_student_name1">Student Name</label>
<input type="text" id="update_student_name1" id="s1_name" name="s1_name" placeholder="Student Name" class="form-control"/>
</div>
<div class="form-group">
<label for="update_student_id2">Student ID 2</label>
<input type="text" id="update_student_id2" id="s2_id" name="s2_id" placeholder="Student ID" class="form-control"/>
<label for="update_student_name2">Student Name</label>
<input type="text" id="update_student_name2" id="s2_name" name="s2_name" placeholder="Student Name" class="form-control"/>
</div>
<div class="form-group">
<label for="update_student_id3">Student ID 3</label>
<input type="text" id="update_student_id3" id="s3_id" name="s3_id" placeholder="Student ID" class="form-control"/>
<label for="update_student_name3">Student Name</label>
<input type="text" id="update_student_name3" id="s3_name" name="s3_name" placeholder="Student Name" class="form-control"/>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" onclick="UpdateUserDetails()" >Save Changes</button>
<input type="hidden" id="project_id">
</div>
</div>
</div>
</div>

open modal after form submit, i dont know ajax :(

I am trying to send data from a form to a modal to verify the data and after proced to send, but this part of the data needs the post from thr form, and this one is not working when it call the modal, I do not know how to use ajax can someone give me a way to go with this thank you
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<?php
if ($_POST) {
$amount = $_POST['precio']*100;
echo $amount;
$miObj->setParameter("DS_MERCHANT_AMOUNT",$amount);
}
?>
<form data-toggle="modal" data-target="#myModal" method="POST" action="" >
<input name="precio" id="precio" />
<input class="btn btn-info" type="submit" >
</form>
<div class="container">
<div class="modal fade" id="myModal" 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">Confirma tu compra</h4>
</div>
<div class="modal-body">
<div id="imagen">IMAGEN COMPRA</div>
<img src="" alt="mando">
<div class="details-area" id="detailsArea">
<h1 style="color:#007acc">Opciones Seleccionadas</h1>
</div>
<div class="form-group">
<label for="nombre">Nombre:</label>
<input type="name" class="form-control" id="nombre">
</div>
<div class="form-group">
<label for="apellido">Apellido</label>
<input type="name" class="form-control" id="Apellido">
</div>
<div class="form-group">
<label for="direccion">Dirección</label>
<input type="address" class="form-control" id="direccion">
</div>
<div class="form-group">
<label for="telefono">Telefono</label>
<input type="phone" class="form-control" id="telefono">
</div>
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" id="email">
</div>
<div align="right"> <h3>Total Compra <span id="AddToCartPriceID2">&nbsp $00.00</span></h3></div>
</div>
<div class="modal-footer">
<form name="frm" action="https://sis-t.redsys.es:25443/sis/realizarPago" method="POST" target="_blank" style="margin-top:10px">
<input name="DS_MERCHANT_AMOUNT" value="<?php echo $amount; ?>"/></br>
<input type="hidden" name="Ds_SignatureVersion" value="<?php echo $version; ?>"/></br>
<input type="hidden" name="Ds_MerchantParameters" value="<?php echo $params; ?>"/></br>
<input type="hidden" name="Ds_Signature" value="<?php echo $signature; ?>"/></br>
<button type="submit" class="btn btn-default" >Confirmar</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</form>
</div>
</div>
</div>
</div>
</div>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<form id="frm" method="POST">
<input name="precio" id="precio" />
<input class="btn btn-info" type="submit" value="Submit" name="submit">
</form>
<div class="modal fade" id="myModal" 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">Confirma tu compra</h4>
</div>
<div class="modal-body">
<div id="imagen">IMAGEN COMPRA</div>
<img src="" alt="mando">
<div class="details-area" id="detailsArea">
<h1 style="color:#007acc">Opciones Seleccionadas</h1>
</div>
<div class="form-group">
<label for="nombre">Nombre:</label>
<input type="name" class="form-control" id="nombre">
</div>
<div class="form-group">
<label for="apellido">Apellido</label>
<input type="name" class="form-control" id="Apellido">
</div>
<div class="form-group">
<label for="direccion">Dirección</label>
<input type="address" class="form-control" id="direccion">
</div>
<div class="form-group">
<label for="telefono">Telefono</label>
<input type="phone" class="form-control" id="telefono">
</div>
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" id="email">
</div>
<div align="right"> <h3>Total Compra <span id="AddToCartPriceID2">&nbsp $00.00</span></h3></div>
</div>
<div class="modal-footer">
<form name="frm" action="https://sis-t.redsys.es:25443/sis/realizarPago" method="POST" target="_blank" style="margin-top:10px">
<input name="DS_MERCHANT_AMOUNT" value="<?php echo $amount; ?>"/></br>
<input type="hidden" name="Ds_SignatureVersion" value="<?php echo $version; ?>"/></br>
<input type="hidden" name="Ds_MerchantParameters" value="<?php echo $params; ?>"/></br>
<input type="hidden" name="Ds_Signature" value="<?php echo $signature; ?>"/></br>
<button type="submit" class="btn btn-default" >Confirmar</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</form>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$("#frm").submit(function(e){
e.preventDefault();
$.ajax({
type : 'POST',
data: $("#frm").serialize(),
url : 'url',
success : function(data){
$("#myModal").modal("show");
}
});
return false;
});
</script>
validated_form.html
<html>
<head>
<script type="text/javascript">
function validate()
{
var error="";
var name = document.getElementById( "name_of_user" );
if( name.value != "" )
{
name = name.value;
document.getElementById( "name" ).innerHTML = name;
return false;
}
}
</script>
</head>
<body>
<form method="POST" action="getdata.php" onsubmit="return validate();">
<input type="text" name="username" id="name_of_user">
<input type="submit" name="submit_form" value="Submit">
</form>
// use id=name in your model form field
<input type="text" id="name" >
</body>
</html>
=====================================
getdata.php
<?php
if( isset( $_POST['submit_form'] ) )
{
validate_data($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = strip_tags($data);
$data = htmlspecialchars($data);
$data = mysqli_real_escape_string($data);
return $data;
}
}
?>

Bootstrap form modal, post values to PHP file

I have a form on a page that allows users to update their information. When they click submit it presents a modal that asks them to enter their password to ensure it's them. However, once they submit the modal it doesn't POST the values to the .php to update their record.
Form and Modal
<div class="container">
<form id="updateInfo" action="update_user.php" method="POST">
<div class="form-group">
<label for "uid">User ID </label>
<input name="uid" id="uid" type="text" class="form-control" value="<?= $_SESSION['uid'] ?>" disabled>
</br>
<label for "firstname">First name </label>
<input name="firstname" id="firstname" type="text" class="form-control" value="<?= $_SESSION['firstname'] ?>">
</br>
<label for "lastname">Surname</label>
<input name="lastname" id="lastname" type="text" class="form-control" value="<?= $_SESSION['lastname'] ?>" >
</br>
<label for "email">Email </label>
<input name="email" id="email" type="email" class="form-control" value="<?= $_SESSION['email'] ?>" required pattern="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*#(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?" title="Email must be in a valid format.">
</br>
<label for "username">Username</label>
<input name="username" id="username" type="text" class="form-control" value="<?= $_SESSION['user'] ?>" >
<span id="msg_username"></span>
</br>
</div>
<button class="btn btn-default" id="submit" type="button" data-toggle="modal" data-target="#myModal" >Submit</button>
<div class="modal fade" id="myModal" role="dialog">
<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">Enter Password</h4>
</div>
<div class="modal-body">
<label for "password">Password</label>
<input name="password" id="password" type="password" class="form-control">
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-default" action="update_user.php" data-dismiss="modal">Submit</button>
</div>
</div>
</div>
</div>
</form>
</div>
PHP file
<?php
require_once 'config.php';
$query = $conn->prepare("UPDATE users SET firstname = :firstname,lastname = :lastname,username = :username ,email = :email WHERE uid = :uid");
$query->bindParam(':firstname', $_POST['firstname']);
$query->bindParam(':lastname', $_POST['lastname']);
$query->bindParam(':username', $_POST['username']);
$query->bindParam(':email', $_POST['email']);
$query->bindParam(':uid', $_POST['uid']);
$result = $query->execute();
if($result)
{
echo "<p>Thank you. Your account has been registered.</p>";
echo $_POST['firstname'];
} else {
echo "<p>Sorry but there was a problem registering your account. Please try again.</p>";
}
?>
You should either wrap the update user button in a form or replace the action attribute by the attribute formaction.
<div class="modal-footer">
<button type="submit" class="btn btn-default" formaction="update_user.php" data-dismiss="modal">Submit</button>
</div>
See documentation of the formaction attribute here or here

Bootstrap model showing me first row data every time

Bootstrap model showing me same data in while loop. When I click any model it shows me first row data, how to fix this please help me.
Here is code
$sql="SELECT * FROM tbl_store order by store_id DESC";
$result=mysqli_query($con, $sql);
while($row=mysqli_fetch_array($result, MYSQLI_ASSOC)) {
#code here
}
HTML code
<td style="vertical-align:middle;">
<a href="#myModal1">
<button type="button" class="btn btn-warning" data-toggle="modal" data-target="#myModal1">Edit</button>
</a>
<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true">
<div class="modal-dialog">
<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="myModalLabel1">Edit Store</h4>
</div>
<div class="modal-body">
<form role="form" action="editStore.php" method="POST" enctype="multipart/form-data">
<!-- text input -->
<div class="row">
<div class="col-md-3 col-xs-3" style="text-align:right; color:#000000;">
<h6>Store Name :</h6>
<br>
<h6 style="margin-bottom:40px; margin-top:-10px;">Description:</h6>
<br>
<h6>Phone:</h6>
<br>
<h6 style="margin-top:0px;">Address:</h6>
<br>
<h6 style="margin-top:0px;">Latitude:</h6>
<br>
<h6 style="margin-top:0px;">Longitude:</h6>
<br>
<h6 style="margin-top:0px;">City:</h6>
<br>
<h6 style="margin-top:0px;">Country:</h6>
<br>
<h6 style="margin-top:0px;">Upload photo:</h6>
<p style="color:red;">*If you want to replace</p>
</div>
<div class="col-md-9 col-xs-9" style="text-align:left; color:#000000;">
<input type="text" class="input form-control" style="width:100%; margin-bottom:10px;" name="title" value="<?php echo $row['store_title']; ?>" required/>
<br>
<textarea class="input input-group" rows="3" style="width:100%; margin-bottom:10px; padding-left:10px;" name="description" required><?php echo $row['store_description']; ?></textarea>
<br>
<input type="tel" class="form-control" style="width:100%; margin-bottom:10px;" name="phone" value="<?php echo $row['store_phone']; ?>"/>
<br>
<input type="text" class="form-control" style="width:100%; margin-bottom:10px;" name="address" value="<?php echo $row['store_address']; ?>" required/>
<br>
<div class="row">
<div class="col-md-6 col-sm-12 pull-left">
<input type="text" class="form-control" style="width:100%; margin-bottom:10px;" max="180" min="0" step="0.00001" name="lat" value="<?php echo $row['store_lat']; ?>" required/>
<input type="text" class="form-control" style="width:100%; margin-bottom:10px;" max="180" min="0" step="0.00001" name="long" value="<?php echo $row['store_long']; ?>" required/>
<input type="text" class="form-control" style="width:100%; margin-bottom:10px;" name="city" value="<?php echo $row['store_city']; ?>" required/>
<input type="text" class="form-control" style="width:100%; margin-bottom:10px;" name="country" value="<?php echo $row['store_country']; ?>" required/>
</div>
<div class="col-md-6 col-sm-12 pull-right">
<img src="<?php echo $row['store_image'];?>" style="float:right;max-height:200px;max-width:200px;">
</div>
<input type="file" style="margin-left:15px; width:93%;" name="photo"/>
<input type="hidden" name="store_id" value="<?php echo $row['store_id'];?>">
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" name="submit">Save changes</button>
</div>
</form>
</div>
</div>
</div>
while Looping your Target has to be unique set of id which equals to id="myModal1". eg.
//inside while loop
target="<?php echo $row['id']; ?>" and id=<?php echo $row['id'];?>

Categories