Submit button does not go to other page - php

I got a problem with my login page.
<?php
session_start();
error_reporting(0);
include("include/config.php");
if(isset($_SESSION['captcha_code']) && isset($_POST['submit']))
{
if ($_SESSION['captcha_code'] == $_POST['captcha']) {
$ret=mysqli_query($con,"SELECT * FROM users WHERE email='".$_POST['email']."' and password='".md5($_POST['password'])."'");
$num=mysqli_fetch_array($ret);
if(mysqli_num_rows($ret) > 0) {
echo "<script>alert('Successfully Registered. You can login now');
window.location.href ='dashboard.php';</script>";
}
} else {
// CAPTCHA code is incorrect, show an error message and allow the user to try again
$_SESSION['errmsg']="Invalid email, password or CAPTCHA code";
$extra="user-login.php";
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']),'/\\');
header("location:http://$host$uri/$extra");
}
exit();
}
?>
<html>
<div class="form-group">
<span class="input-icon">
<input type="text" class="form-control" name="email" placeholder="Email">
<i class="fa fa-user"></i> </span>
</div>
<div class="form-group form-actions">
<span class="input-icon">
<input type="password" class="form-control password" name="password" placeholder="Password">
<i class="fa fa-lock"></i>
</span><a href="forgot-password.php">
Forgot Password ?
</a>
</div>
<div class="form-actions">
<div class="form-group form-actions">
<img src="captcha.php" alt="Captcha Code" id="captchaImg">
<i class="fa fa-fresh"></i>
<input type="text" class="form-control" name="captcha" id = "captcha_code" placeholder="Enter above captcha">
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary pull-right" name="submit">Login <i class="fa fa-arrow-circle-right"></i>
</button>
</div>
</html>
This page from my login.php. When the user clicks the submit button, the user is supposed to go to dashboard.php. In my case, it only generated a script alert but stayed on the login page. This happens when users insert a valid email, password, and captcha. I hope I can get a solution for this code. Thank you and sorry for my English.

Related

PHP prepare-statement User Change password

This is the html code for the change password page. When I click change password from the user registration table, it bring me here and it works perfectly but when you use the option of the user change password which leads you directly to this place, saving it doesn't work. I believe it's got to deal with the User ID as key since from the table is selected via ID. But when i use setting - user change password, it doesn't do anything after saving password change, it doesn't reflect anything
<div class="col-lg-6">
<div class="col-sm-12">
<br/>
<h3 class="page-title">Change Password</h3>
</div>
<div class="card-box">
<div class="form-group">
<label for="userName">User Name</label>
<input type="text" name="uname" parsley-trigger="change" required placeholder="Enter user name" class="form-control" id="uname" name="uname" value="<?php echo $actordetails->ACT_USERNAME;?>" readonly >
</div>
<div class="form-group">
<label for="pass1">New Password<span style="color:#F00">*</span></label>
<input id="pass1" type="password" placeholder="Password" name="inputpassword" required class="form-control">
</div>
<div class="form-group">
<label for="passWord2">Confirm New Password <span style="color:#F00">*</span></label>
<input data-parsley-equalto="#pass1" type="password" required placeholder="Password" class="form-control" id="password2">
</div>
<div class="form-group text-right m-b-0">
<button class="btn btn-success waves-effect waves-light" type="submit" onclick="document.getElementById('viewpage').value='savepwd';document.getElementById('view').value='';document.getElementById('fdsearch').value='';document.myform.submit()">
Save
</button>
<button class="btn btn-default waves-effect waves-light m-l-5" onclick="document.getElementById('view').value='';document.getElementById('viewpage').value='';document.myform.submit()">
Cancel
</button>
</div>
</div>
</div>
</form >
and this is the controller code to process the information. The encryption uses username and password with salt for your information.. Any help would be appreciated
<?php
$crypt = new cryptCls();
switch(strtolower($viewpage)) {
case "changepwd":
print_r($_POST);
$stmt = $sql->Execute($sql->Prepare("
SELECT ACT_USERNAME,ACT_ID
FROM gm_actors
WHERE ACT_ID=".$sql->Param('a')),array($keys));
print $sql->ErrorMsg();
if($stmt->RecordCount()>0){
$editobj = $stmt->FetchNextObject();
$uname = $actordetails->ACT_USERNAME;
}
break;
case "savepwd":
print_r($_POST);
$duplicatekeeper = $session->get("post_key");
if($action_key != $duplicatekeeper){
$session->set("post_key",$action_key);
if(!empty($inputpassword) && !empty($keys) ) {
$inputpassword = $crypt->loginPassword($uname,$inputpassword);
$stmt = $sql->Execute($sql->Prepare("
UPDATE gm_actors
SET ACT_USERPASSWORD=".$sql->Param('b')."
WHERE ACT_ID=".$sql->Param('d')." "),
array($inputpassword,$actordetails->ACT_ID));
$msg = "Password has been changed successfully.";
$status = "success";
// $activity = ' Agent'.$keys.' password changed .';
// $engine->setEventLog("032",$activity);
}else if($inputpassword!==$confirmpassword){
$msgs="Sorry! Passwords Do not Match.";
$target ='changepwd';
} else {
$msg = "Unsuccessfully: All fields are required.";
$status = "error";
$view ="changepwd";
}
}
break;
}
$stmtusers = $sql->Execute($sql->Prepare("
SELECT ACT_SURNAME,ACT_ID,ACT_OTHERNAMES,
ACT_USERNAME,ACT_STATUS,ACT_EMAIL,ACT_PHONE,
ACT_ACCESS_LEVEL,ACL_NAME
FROM gm_actors
left join gm_actors_level on ACT_ACCESS_LEVEL=ACL_NUMBER
WHERE ACT_ACCESS_LEVEL !='1'
AND ACT_STATUS !='4'
ORDER BY ACT_SURNAME "));
print $sql->ErrorMsg();
include("model/js.php");
include('public/alertmessage/message.php');
?>

Download a file with alert box using PHP

I'm having a submit form where the form includes the following text fields
First name
Last name
Email
Password
When user enters the general password of "DEFAULTDOC" it will automatically download the file. But if not then it will show an alert box that says "Sorry your password is incorrect".
My codes is working fine. But the alert box in
"You are now verified the file will automatically download."
Doesn't show but the downloading of file is working also the inserting of data is working too. Except of showing the alert box. What could be the reason why the alert box doesn't show up?
here's my code: (dlform.php)
<?php
$database = 'db';
$host = 'localhost';
$username = 'username';
$password = 'password';
$e = $_POST['e'];
$p = $_POST['p'];
$f = $_POST['f'];
$l = $_POST['l'];
if($_POST['p'] == "DEFAULTDOC"){
try
{
$connect = new PDO("mysql:host=$host;dbname=$database", $username, $password);
$connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = "INSERT INTO dlform VALUES('','$p','$f','$l','$e')";
$data = $connect->query($query);
header('Content-type: application/vnd.ms-word');
header('Content-disposition: attachment; filename=InformationSheet.docm');
?>
<script>
alert('You are now verified the file will automatically download.');
window.location.href='downloadform.php';
</script>
<?php
}
catch(PDOException $error)
{
$error->getMessage();
}
}else{
?>
<script>
alert('Sorry your password is incorrect.');
window.location.href='downloadform.php';
</script>
<?php
}
?>
Here's my html code:(downloadform.php)
<div class="container" style="margin: 0 auto; width: 600px;margin-top: 10%;">
<center>
<img src="images/menu_bar_logo.png" alt ="" style="width: 300px;"/></center>
<br>
<div class="row">
<b>Note:</b>Fill up the following fields to get your form<br>
<form method="post" action="dlform.php">
<br>
<div class="input-group">
<span class="input-group-addon">First name</span>
<input id="msg" type="text" class="form-control" name="f" placeholder="First name">
</div>
<div class="input-group">
<span class="input-group-addon">Last name</span>
<input id="msg" type="text" class="form-control" name="l" placeholder="Last name">
</div>
<Br>
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input id="email" type="email" class="form-control" name="e" placeholder="Email">
</div>
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
<input id="password" type="password" class="form-control" name="p" placeholder="Password">
</div>
<br>
<input type="submit" name="submit" class="btn btn-primary" value="Submit">
</form>
</div>
You try to use html tag while dlform.php only has php code. It won't work. Try to set the message into SESSION.
Your code
<script>
alert('You are now verified the file will automatically download.');
window.location.href='downloadform.php';
</script>
Change your code into php
$_SESSION['message'] = 'You are now verified the file will automatically download.';
header('Location: downloadform.php');
The same goes for incorrect password one.
And in your downloadform.php, add this code.
<?php if (isset($_SESSION['message'])): ?>
<div class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Message</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p><?php echo $_SESSION['message']; ?></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Save changes</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<?php unset($_SESSION['message']); ?>
<?php endif; ?>
This code is in bootstrap style. This code is not an alert, but a modal similar to alert. It will show up if there is a message from dlform.php. After the message is shown, destroy the message session so it won't appear each time downloadform.php is reload, unless you submit the form.

Codeigniter multiple form in one page with separate validation

I have two form in one page. When I click on the submit button of form one, the validation error shows on both forms. How could show separate validation errors on each form?
This is my view:
<?php echo form_open('user_signup/login',['class'=>'login-form','id'=>'submit_form']);
echo validation_errors();?>
<h3 class="form-title font-green">Sign In</h3>
<div class="alert alert-danger display-hide">
<button class="close" data-close="alert"></button>
<span> Enter any username and password. </span>
</div>
<div class="form-group">
<!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
<label class="control-label visible-ie8 visible-ie9">Email</label>
<?php echo form_input(['name'=>'email1','type'=>'text','style'=>'text-transform: capitalize;','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Email','value'=>set_value('email1')]); ?>
</div>
<div class="form-group">
<label class="control-label visible-ie8 visible-ie9">Password</label>
<?php echo form_input(['name'=>'pass','type'=>'password','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Password']); ?>
</div>
<div class="form-actions">
<?php echo form_submit('submit', 'Submit',"class='btn green uppercase'" ); ?>
Forgot Password?
</div>
<div class="login-options">
<h4>Or login with</h4>
<ul class="social-icons">
<li>
<a class="social-icon-color facebook" data-original-title="facebook" href="javascript:;"></a>
</li>
<li>
<a class="social-icon-color twitter" data-original-title="Twitter" href="javascript:;"></a>
</li>
<li>
<a class="social-icon-color googleplus" data-original-title="Goole Plus" href="javascript:;"></a>
</li>
<li>
<a class="social-icon-color linkedin" data-original-title="Linkedin" href="javascript:;"></a>
</li>
</ul>
</div>
<div class="create-account">
<p>
Create an account
</p>
</div>
</form>
<!-- END LOGIN FORM -->
<!-- BEGIN FORGOT PASSWORD FORM -->
<form class="forget-form" action="http://keenthemes.com/preview/metronic/theme/admin_2/index.html" method="post">
<h3 class="font-green">Forget Password ?</h3>
<p> Enter your e-mail address below to reset your password. </p>
<div class="form-group">
<input class="form-control placeholder-no-fix" type="text" autocomplete="off" placeholder="Email" name="email" /> </div>
<div class="form-actions">
<button type="button" id="back-btn" class="btn green btn-outline">Back</button>
<button type="submit" class="btn btn-success uppercase pull-right">Submit</button>
</div>
</form>
<!-- END FORGOT PASSWORD FORM -->
<!-- BEGIN REGISTRATION FORM -->
<?php echo form_open('user_signup/login',['class'=>'register-form','id'=>'register_form']);
?>
<h3 class="font-green">Sign Up</h3>
<p class="hint"> Enter your personal details below: </p>
<div class="form-group">
<label class="control-label visible-ie8 visible-ie9">Roll NO</label>
<?php echo form_input(['name'=>'rollno','type'=>'text','style'=>'text-transform: capitalize;','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Rollno','value'=>set_value('rollno')]); ?>
</div>
<div class="form-group">
<!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
<label class="control-label visible-ie8 visible-ie9">Email</label>
<?php echo form_input(['name'=>'email2','type'=>'text','style'=>'text-transform: capitalize;','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Email','value'=>set_value('email2')]); ?>
</div>
<div class="form-actions">
<button type="button" id="register-back-btn" class="btn green btn-outline">Back</button>
<?php echo form_submit('register', 'register',"class='btn btn-success uppercase pull-right'" ); ?>
This is my controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User_signup extends CI_Controller {
public function index()
{
$this->load->view('User/signup');
}
public function login()
{
if ($this->input->post('submit_form')) {
$rules['email1'] = 'required';
$rules['pass'] = 'required';
$this->form_validation->set_rules($rules);
}
else if ($this->input->post('register_form')) {
$rules['rollno'] = 'required';
$rules['email2'] = 'required';
$this->validation->set_rules($rules);
}
if (!$this->form_validation->run()) {
$this->load->view('User/signup');
}
else {
if ($this->input->post('submit_form'))
echo 'Form 1 posted !';
else if ($this->input->post('register_form'))
echo 'Form 2 posted !';
}
}
}
There are two things you need to concern about that. First passing action in HTML form. Second is, getting those parameters and code accordingly in your controller's action.
<?php echo form_open('user_signup/login/form-1',['class'=>'login-form','id'=>'submit_form']);
echo validation_errors();?>
<h3 class="form-title font-green">Sign In</h3>
<div class="alert alert-danger display-hide">
<button class="close" data-close="alert"></button>
<span> Enter any username and password. </span>
</div>
<div class="form-group">
<!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
<label class="control-label visible-ie8 visible-ie9">Email</label>
<?php echo form_input(['name'=>'email1','type'=>'text','style'=>'text-transform: capitalize;','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Email','value'=>set_value('email1')]); ?>
</div>
<div class="form-group">
<label class="control-label visible-ie8 visible-ie9">Password</label>
<?php echo form_input(['name'=>'pass','type'=>'password','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Password']); ?>
</div>
<div class="form-actions">
<?php echo form_submit('submit', 'Submit',"class='btn green uppercase'" ); ?>
Forgot Password?
</div>
<div class="login-options">
<h4>Or login with</h4>
<ul class="social-icons">
<li>
<a class="social-icon-color facebook" data-original-title="facebook" href="javascript:;"></a>
</li>
<li>
<a class="social-icon-color twitter" data-original-title="Twitter" href="javascript:;"></a>
</li>
<li>
<a class="social-icon-color googleplus" data-original-title="Goole Plus" href="javascript:;"></a>
</li>
<li>
<a class="social-icon-color linkedin" data-original-title="Linkedin" href="javascript:;"></a>
</li>
</ul>
</div>
<div class="create-account">
<p>
Create an account
</p>
</div>
</form>
<!-- END LOGIN FORM -->
<!-- BEGIN FORGOT PASSWORD FORM -->
<form class="forget-form" action="http://keenthemes.com/preview/metronic/theme/admin_2/index.html" method="post">
<h3 class="font-green">Forget Password ?</h3>
<p> Enter your e-mail address below to reset your password. </p>
<div class="form-group">
<input class="form-control placeholder-no-fix" type="text" autocomplete="off" placeholder="Email" name="email" /> </div>
<div class="form-actions">
<button type="button" id="back-btn" class="btn green btn-outline">Back</button>
<button type="submit" class="btn btn-success uppercase pull-right">Submit</button>
</div>
</form>
<!-- END FORGOT PASSWORD FORM -->
<!-- BEGIN REGISTRATION FORM -->
<?php echo form_open('user_signup/login/form-2',['class'=>'register-form','id'=>'register_form']);
?>
<h3 class="font-green">Sign Up</h3>
<p class="hint"> Enter your personal details below: </p>
<div class="form-group">
<label class="control-label visible-ie8 visible-ie9">Roll NO</label>
<?php echo form_input(['name'=>'rollno','type'=>'text','style'=>'text-transform: capitalize;','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Rollno','value'=>set_value('rollno')]); ?>
</div>
<div class="form-group">
<!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
<label class="control-label visible-ie8 visible-ie9">Email</label>
<?php echo form_input(['name'=>'email2','type'=>'text','style'=>'text-transform: capitalize;','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Email','value'=>set_value('email2')]); ?>
</div>
<div class="form-actions">
<button type="button" id="register-back-btn" class="btn green btn-outline">Back</button>
<?php echo form_submit('register', 'register',"class='btn btn-success uppercase pull-right'" ); ?>
Note: Check form actions
Here is your updated controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User_signup extends CI_Controller {
public function index()
{
$this->load->view('User/signup');
}
public function login()
{
// Checking passed 3rd parameter in URI string.
$submitted_form = $this->uri->segment(3)?$this->uri->segment(3):false;
if ($submitted_form == 'form-1') {
$rules['email1'] = 'required';
$rules['pass'] = 'required';
$this->form_validation->set_rules($rules);
}
if ($submitted_form == 'form-2') {
$rules['rollno'] = 'required';
$rules['email2'] = 'required';
$this->validation->set_rules($rules);
}
if ($this->form_validation->run()) {
if ($submitted_form == 'form-1')
echo 'Form 1 posted !';
else if ($submitted_form == 'form-1')
echo 'Form 2 posted !';
}
$this->load->view('User/signup');
}
}
Let me know if you have any confusion.
Submit by Jquery. For Example in your view
<form id="form1" action="" method="post">
<label>Username</label>
<input type="text" name="username">
<label>Password</label>
<input type="password" name="password">
<input type="hidden" name="form_type" value="login">
<button type="submit" onClick="login()">Login</button>
</form>
<form id="form2" action="" method="post">
<label>Username</label>
<input type="text" name="username">
<label>Password</label>
<input type="password" name="password">
<label>Email</label>
<input type="email" name="email">
<input type="hidden" name="form_type" value="register">
<button type="submit" onClick="register()">Login</button>
</form>
Jquery Script
<script>
function login()
{
$('#form1').submit();
}
function register()
{
$('#form2').submit();
}
</script>
Now in your controller
if($_POST)
{
if($_POST['form_type']=='login')
{
// Validate Login
}
elseif($_POST['form_type']=='register')
{
// validate register
}
}

PHP Doesn't post my form values

I've been scratching my head for a hour now and can't figure out why php doesn't post my form values.
Code
<!-- Login -->
<div class="login__block toggled" id="l-login">
<div class="login__block__header">
<i class="zmdi zmdi-account-circle"></i>
Hi there! Please Sign in
<div class="actions login__block__actions">
<div class="dropdown">
<i class="zmdi zmdi-more-vert"></i>
<ul class="dropdown-menu pull-right">
<li><a data-block="#l-register" href="#">Create an account</a></li>
<li><a data-block="#l-forget-password" href="#">Forgot password?</a></li>
</ul>
</div>
</div>
</div>
<div class="login__block__body">
<div class="form-group form-group--float form-group--centered form-group--centered">
<input type="text" class="form-control" name="email">
<label>Email Address</label>
<i class="form-group__bar"></i>
</div>
<div class="form-group form-group--float form-group--centered form-group--centered">
<input type="password" class="form-control" name="password">
<label>Password</label>
<i class="form-group__bar"></i>
</div>
<button type="submit" class="btn btn--light btn--icon m-t-15"><i class="zmdi zmdi-long-arrow-right"></i></button>
</div>
<?php
if(isset($_POST['login'])) {
if(isset($_POST['email']) && isset($_POST['password']) &&
is_string($_POST['email']) && is_string($_POST['password']) &&
!empty($_POST['email']) && !empty($_POST['password'])) {
$email = stripslashes(strip_tags($_POST['email']));
$password = md5($_POST['password']);
$stmt = $pdo->prepare('SELECT * FROM users WHERE UserEmail = :UserEmail');
$stmt->bindParam(':UserEmail', $email);
$stmt->execute();
if($stmt->rowCount() > 0) {
$stmt = $pdo->prepare('SELECT * FROM users WHERE UserEmail = :UserEmail AND UserPassword = :UserPassword');
$stmt->execute(array(':UserEmail' => $email, ':UserPassword' => $password));
if($stmt->rowCount() > 0) {
$row = $stmt->fetch();
$UserLevel = $row['UserLevel'];
if($UserLevel == 'banned') {
$display->ReturnError('Your account has been suspended.');
return false;
}
$UserID = $row['UserID'];
$time = time();
$IPAddress = $_SERVER['REMOTE_ADDR'];
$_SESSION['auth'] = $UserID;
$stmt = $pdo->prepare('INSERT INTO logs (LogUserID, LogDate, LogIPAddress) VALUES (:LogUserID, :LogDate, :LogIPAddress)');
$stmt->execute(array(':LogUserID' => $UserID, ':LogDate' => $time, ':LogIPAddress' => $IPAddress));
$display->ReturnSuccess('You was successfully logged in.');
$settings->forceRedirect('index.php', 2);
} else {
$display->ReturnError('Invalid user credentials.');
}
} else {
$display->ReturnError('User with these credentials does not exists.');
}
}
}
?>
</div>
Note that I'm very new to PHP and it would mean the world to me if you could help me out! Thank you.
Submit Button only works when it is inside form tag.
Your code does not have any form tag
Try this
<form action="" >
<!-- Login -->
<!--your code here -->
</form>
add form attributes like this
<div class="login__block__body">
<form action="url which will process form" method="POST">
<div class="form-group form-group--float form-group--centered form-group--centered">
<input type="text" class="form-control" name="email">
<label>Email Address</label>
<i class="form-group__bar"></i>
</div>
<div class="form-group form-group--float form-group--centered form-group--centered">
<input type="password" class="form-control" name="password">
<label>Password</label>
<i class="form-group__bar"></i>
</div>
<button type="submit" class="btn btn--light btn--icon m-t-15"><i class="zmdi zmdi-long-arrow-right"></i></button>
</form>
</div>
All <input> tags must be within the <form> tags.
<form action="" method="post"> //Submits form to same page
<input/>
<input/>
<button type="submit" class="btn btn--light btn--icon m-t-15"><i class="zmdi zmdi-long-arrow-right"></i></button>
</form>
When you "submit" this form, it will POST all of the input values within the form, which you retrieve from the $_POST['name_of_input'] variables
I would recommend learning HTML before PHP.

PHP Variables passed through a pop up window

I have a page that pulls from a database and shows rows of thumbnail pictures and a small bit of information about them. I have a "Read More" button for each person. But you need to sign in to be able to read more about that person.
When you press "Read More" a pop up window opens offering the user to either "sign in" (already have an account) or "create a new account".
After a user signs in I would like that page to redirect to the specific person's profile. My issue is I can't figure out where to store that id variable. How do I pass that variable to the popup window and then on to the redirect link.
// User Log In Form
if (isset($_POST['submit']) && $_POST['submit'] == 'userSignIn') {
if($_POST['usersEmail'] == '') {
$msgBox = alertBox("Your User Email Address is required.", "<i class='fa fa-times-circle'></i>", "danger");
} else if($_POST['password'] == '') {
$msgBox = alertBox("Your Account Password is required.", "<i class='fa fa-times-circle'></i>", "danger");
} else {
// Check if the User account has been activated
$usersEmail = (isset($_POST['usersEmail'])) ? $mysqli->real_escape_string($_POST['usersEmail']) : '';
$check = $mysqli->query("SELECT isActive FROM users WHERE usersEmail = '".$usersEmail."'");
$row = mysqli_fetch_assoc($check);
// If the account is active - allow the login
if ($row['isActive'] == '1') {
$usersEmail = $mysqli->real_escape_string($_POST['usersEmail']);
$password = encryptIt($_POST['password']);
if($stmt = $mysqli -> prepare("
SELECT
userId,
usersEmail,
usersName
FROM
users
WHERE
usersEmail = ? AND password = ?
")) {
$stmt -> bind_param("ss",
$usersEmail,
$password
);
$stmt -> execute();
$stmt -> bind_result(
$userId,
$usersEmail,
$usersName
);
$stmt -> fetch();
$stmt -> close();
if (!empty($userId)) {
session_start();
$_SESSION["userId"] = $userId;
$_SESSION["usersEmail"] = $usersEmail;
$_SESSION["usersName"] = $usersName;
$id = **NEED PERSON'S ID**
header("Location: http://scout.militarypropertyproject.com/index.php?page=scout_detail&id=".$id."");
} else {
$msgBox = alertBox("Login Failed. Please check your entries." , "<i class='fa fa-times-circle'></i>", "danger");
}
}
// Update Last Visited Date for User
$lastVisited = date("Y-m-d H:i:s");
$sqlStmt = $mysqli->prepare("
UPDATE
users
SET
lastVisited = ?
WHERE
userId = ?
");
$sqlStmt->bind_param('ss',
$lastVisited,
$userId
);
$sqlStmt->execute();
$sqlStmt->close();
} else if ($row['isActive'] == '0') {
// If the account is not active, show a message
$msgBox = alertBox("Your Account is currently inactive, and you can not log in.", "<i class='fa fa-warning'></i>", "warning");
} else {
// No account found
$msgBox = alertBox("No Account found for that Email Address & Password.", "<i class='fa fa-times-circle'></i>", "danger");
}
}
}
//////////////////// User's displayed in rows ////////////////////////////
<div class="row">
<div id="FilterContainer">
<?php foreach ($categories as $category) { ?>
<div class="col-md-4">
<div id = "user-square">
<div class="avatar">
<center> <img src="<?php echo '../'.$avatarDir.$category['usersAvatar']; ?>" class="publicAvatar" /></center>
</div>
<div class = "user_bio_heading"><?php echo $category['name']; ?>
<?php $starNumber = $category['avgstars'];
for($x=1;$x<=$starNumber;$x++) {
echo '<i class="fa fa-star"></i>';
}
if (strpos($starNumber,'.')) {
echo '<i class="fa fa-star-half"></i>';
$x++;
}
while ($x<=5) {
echo '<i class="fa fa-star-o"></i>';
$x++;
}
?>
</div>
<div class = "user_bio"><?php echo substr($category['bio'], 0, 150) ?>...
<?php $_SESSION["scoutUserId"] = $category['id'];
?>
</div>
<a data-toggle="modal" href="#signIn" class="btn btn-warning btn-sm btn-icon"><i class="fa fa-unlock-alt"></i> Read More</a>
</div>
</div>
<?php }
?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div><!-- row -->
/////////////////////////////// POP UP WINDOW //////////////////////////
<div class="modal fade" id="signIn" tabindex="-1" role="dialog" aria-labelledby="newAccount" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header success">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i></button>
<h4 class="modal-title">Sign In</h4>
</div>
<form action="" method="post">
<p>All ready have a user account? Please Sign in.</p>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envelope"></i></span>
<input type="email" class="form-control" required="" placeholder="User's Email Address" name="usersEmail" />
</div>
<br />
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-lock icon-lock"></i></span>
<input type="password" class="form-control" required="" placeholder="Account Password" name="password" />
</div>
<div class="row mt10">
<div class="col-md-4">
<p><small><a data-toggle="modal" href="#resetPassword">Reset Password?</a></small></p>
</div>
</div>
<div class="modal-footer">
<input type="hidden" name="captcha" value="" />
<button type="input" name="submit" value="userSignIn" class="btn btn-success btn-icon"><i class="fa fa-check-square-o"></i> Sign In</button>
<button type="button" class="btn btn-warning btn-icon" data-dismiss="modal"><i class="fa fa-times-circle"></i> Cancel</button>
</div>
<hr>
<p>Don't have an account with us yet? No worries we'll get you set up real quick!</p>
<button type="input" name="submit" value="newAccount" class="btn btn-success btn-icon"><i class="fa fa-check-square-o"></i> Create Account</button>
</form>
</div>
</div>
</div>
<div class="col-md-8">
<span class="pull-right">
<button type="input" name="submit" value="userSignIn" class="btn btn-success btn-sm btn-icon"><i class="fa fa-sign-in"></i> Sign In</button>
<a data-toggle="modal" href="#newAccount" class="btn btn-warning btn-sm btn-icon"><i class="fa fa-unlock-alt"></i> Create New Account</a>
</span>
</div>
</div>
</form>
///////////////////////////////////////////////
Thanks in advance for any help you can provide.
How about you pass the user's id in Javascript and then interject it as hidden field into the form so when user successfully logs in, you know where they want to go.
So first add new data attribute to this code:
<a data-toggle="modal" href="#signIn" class="btn btn-warning btn-sm btn-icon"><i class="fa fa-unlock-alt"></i> Read More</a>
So it becomes (note data-uid):
<a data-toggle="modal" href="#signIn" class="btn btn-warning btn-sm btn-icon"><i class="fa fa-unlock-alt" data-uid="<?=$category['id']?>"></i> Read More</a>
Then in popup code where you have:
<input type="hidden" name="captcha" value="" />
You add new hidden input tag:
<input type="hidden" name="captcha" value="" />
<input id="wanted_user" type="hidden" name="userid" value="" />
Finally, in javascript modal popup code you interject the data-uid to the hidden field. You get the correct id by listening who triggered the event.
$('#signIn').on('show.bs.modal', function (e) {
var target_user = $(e.relatedTarget).data('uid');
$('#wanted_user').val(target_user);
});
Please note that this example might have some bugs and you need to debug it.
CodePen for you

Categories