I use the below codes for email conformation:
using URL: /my_web/back-end/email-verify.php?email=email#gmail.com&code=Vruxc9JQwZEKjbz3HbZ2KlGPX10mJneDmH67hILqFooXeJIQb9
After the verification how can I get the jQuery to pop up on the index page?
Is there any possible way to get PHP echo value to jQuery?
if(isset($_GET['email']) && !empty($_GET['email']) AND isset($_GET['code']) && !empty($_GET['code'])){
// Verify data
$email = mysqli_escape_string($conn,$_GET['email']); // Set email variable
$hash = mysqli_escape_string($conn,$_GET['code']); // Set hash variable
$sql="SELECT * FROM users WHERE user_email='".$email."' AND hashid='".$hash."' AND valied_user_1='0'";
$search = mysqli_query($conn,$sql);
if(mysqli_num_rows($search) > 0){
// We have a match, activate the account
$update="UPDATE users SET valied_user_1='1' WHERE user_email='".$email."' AND hashid='".$hash."' AND valied_user_1='0'";
mysqli_query($conn,$update);
echo"success";
}else{
///other echo
}
jQuery Function:
$(document).ready(function(){
if(success){
$('#alert').addClass('alert-success alert-dismissible fade show');
$('#alertText').html('Your account has been activated, you can now login.');
$('.modal4').show();
}
});
HTML Modal4:
<div class="modal4">
<div class="container alert-popup">
<div id="alert" class="alert">
<button type="button" id="alertcloss" class="close">×</button>
<p id="alertText"></p>
</div>
</div>
</div>
Redirect the email_validation.php to index.php page with the GET parameters.
http://sample.com/index.php?success=1 and on the index.php page do like
<div class="modal4">
<div class="container alert-popup">
<div id="alert" class="alert">
<button type="button" id="alertcloss" class="close">×</button>
<p id="alertText"></p>
</div>
</div>
</div>
<?php
if(isset($_GET['success']) {
?>
$(document).ready(function(){
$('#alert').addClass('alert-success alert-dismissible fade show');
$('#alertText').html('Your account has been activated, you can now login.');
$('.modal4').show();
});
<?php
}
?>
Related
I need to be able to update my sql table from open to close task.
I already wrote code for this but it is not working properly. On the modal it shows 2 'continue' buttons and right now the task table contains two tasks. Can somebody help me?
This is what the modal looks like:
and this is my code:
<?php
if (isset($_POST["closetask"])) {
$close_task_id = mysqli_real_escape_string($con, $_POST["close_task_id"]);
$sql = "UPDATE task SET task_status='closed' WHERE id_task='$close_task_id'";
$result = mysqli_query($con, $sql);
if ($result) {
$_SESSION['success'] = "Task closed";
$_SESSION['text'] = "Task has been closed successfully";
$_SESSION['icon'] = "success";
} else {
$_SESSION['success'] = "Error";
$_SESSION['text'] = "Unkown error, please try again";
$_SESSION['icon'] = "error";
}
}
?>
<?php
$query = "SELECT * FROM task ORDER BY id_task DESC";
$result = mysqli_query($con, $query);
?>
<!-- reject button -->
<form action="task-view.php" method="post" enctype="multipart/form-data">
<div id="rejectModal" class="modal fade" role="dialog" >
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Close this task?</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<div class="d-flex align-items-center justify-content-center form-group" >
<p class="align-items-center text-center" for="company">This button means closing the task. Are you sure you want to continue?</p>
</div>
</div>
<div class="modal-footer">
<?php
while ($row = mysqli_fetch_array($result)) {
if ($row['task_status'] == 'open'){
$check_task = '
<input type="text" name="close_task_id" class="form-control" value="' . $row["id_task"] . '" hidden>
<button class="btn btn-success" type="submit" name="closetask" class="btn btn-success">Continue</button>
</button>
';
}
echo '
<br>
' . $check_task . '
';
}
?>
</div>
</div>
</div>
</div>
</div>
</form>
<!-- end of reject button-->
<?php
if (isset($_SESSION['success']) && $_SESSION['success'] != '') {
?>
<script>
swal({
title: "<?php echo $_SESSION['success']; ?>",
text: "<?php echo $_SESSION['text']; ?>",
icon: "<?php echo $_SESSION['icon']; ?>",
button: "OK",
});
</script>
<?php
unset($_SESSION['success']);
}
?>
Well, after going through your code snippet,
I could see this query
$query = "SELECT * FROM task ORDER BY id_task DESC";
$result = mysqli_query($con, $query);
meaning this fetches all records in the task table, the two continue buttons you see are coming from the while loop
while ($row = mysqli_fetch_array($result)) {
....
}
it logically implies you have two records or rows in your database task table and all the records where retrieved from the table.
I have a chatting system project php with a nav and has a child div called inbox where inbox has a children div.message and div.message__requests:
<div class="inbox">
<div class="messages">
<header>
<nav>
<a id="messages"><b>Messages</b></a><a id="messageRequests"><b>Message Requests</b></a>
</nav>
<hr>
<form action="includes/chatsearch-inc.php" method="POST">
<input type="text" name="search" placeholder="Search a user or applicant\'s name">
<button name="submit"><i class="fa fa-search"></i></button>
</form>
</header>
<section>';
$sql = "SELECT * FROM users WHERE NOT usersId ='".$_SESSION['userid']."';";
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_assoc($result)) {
echo '<div class="user__container">
<input type="hidden" data-userid="'.$row['usersId'].'">
<img src="profilepic/'.$row['usersProfilePic'].'">
<div class="user">
<p><b>'.$row['usersName'].'</b></p>
<p class="message">You: dssasdas</p>
</div>
</div>
<hr>';
}
echo '</section>
</div>
<div class="message__requests">
<nav>
<a id="messages"><b>Messages</b></a><a id="messageRequests"><b>Message Requests</b></a>
</nav>
<section>
<div class="user__container">
<img src="profilepic/'.$profilepic.'">
<div class="user">
<p><b>'.$_SESSION['username'].'</b></p>
<p class="message">asdasdsd</p>
</div>
</div>
<hr>
<div class="user__container">
<img src="profilepic/'.$profilepic.'">
<div class="user">
<p><b>'.$_SESSION['username'].'</b></p>
<p class="message">asdasdsd</p>
</div>
</div>
<hr>
</section>
</div>
</div>
Where div.messages shows the users inbox like the home screen of facebook messenger app.
If I click the said nav, the inbox will pop in the middle of the screen and the div.message is the default content.
Now when I click a div.user__container inside my div.messages, I can load the user chat box, like when you click a user in facebook messenger inside the div.messages, replacing all the content of div.messages with what I have in my other php file (simulating a real time chat box):
$sql = "SELECT * FROM messages AS m LEFT JOIN users AS u ON m.outgoingUsersId = u.usersId WHERE (incomingUsersId = '$incoming' AND outgoingUsersId = '$outgoing') OR (incomingUsersId = '$outgoing' AND outgoingUsersId = '$incoming') ORDER BY msgId DESC;";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
if ($row['outgoingUsersId'] == $outgoing) {
$output .= '<div class="chat outgoing">
<div class="message">
<p>'.$row['msgContent'].'</p>
</div>
</div>';
}
else {
$output .= '<div class="chat incoming">
<img src="profilepic/'.$row['usersProfilePic'].'">
<div class="message">
<p>'.$row['msgContent'].'</p>
</div>
</div>';
}
}
echo $output;
}
And I can achieve this all by my jquery call:
$('section .user__container').click(function() {
var userid = $(this).children('input').data('userid');
$('.inbox .messages').load('includes/ajax-load/chatpage-aload.php',
{
usersid : userid
}, function() {
$('.user__inbox header i').click(function() {
// I want to load back to div.messages content
});
var sender = $('#chatForm #chatSender').val();
var receiver = $('#chatForm #chatReceiver').val();
setInterval(() => {
$.post('includes/ajax-func/getchat-afunc.php', {
outgoingUsersId : sender,
incomingUsersId : receiver
}, function (response) {
$('.user__inbox section').html(response);
});
}, 500
);
$('#chatForm').submit(function(e) {
e.preventDefault();
var message = $('#chatForm input[type="text"]').val();
$.post('includes/ajax-func/insertchat-afunc.php', {
outgoingUsersId : sender,
incomingUsersId : receiver,
message : message
}, function (data) {
$('#chatForm input[type="text"]').val("");
});
});
});
});
My question is, how can I go back to the main content of div.messages (like how users in messenger app can go bck to the home screen when the click the back button beside the users info in their header) without reloading the whole webpage, when I click the:
$('.user__inbox header i').click(function() {
// I want to load back to div.messages content
});
Or any recommendations to my code? Thanks
I need to get the new session value after some second using PHP. My code is below.
<button class="btn nextbtnbgdiv open2" type="button">Next <span class="fa fa-arrow-right"></span></button>
<div class="fyndspacecategory fyndsheightsubc nano">
<div class="nano-content">
<?php
$cat_id= $_SESSION['cid'];
?>
</div>
</div>
Here when user is clicking on next button the div section is opening and the the value is fetching from session. Here i need after some second always the updated $_SESSION['cid'] will fetch at each time click on next button.
In order to fetch the updated $_SESSION['cid'] you will need to make a call to the server to return this value, you can do so by embedding the value into an element i.e.
Back-end (i.e. get_session.php):
<html>
<body>
<div id="session"><?= $_SESSION['cid'] ?></div>
</body>
</html>
Front-end:
<button class="btn nextbtnbgdiv open2" type="button">Next <span class="fa fa-arrow-right"></span></button>
<div class="fyndspacecategory fyndsheightsubc nano">
<div class="nano-content"><?php $cat_id= $_SESSION['cid']; ?></div>
</div>
<script>
jQuery(function($) {
$(document).on( 'click', '.nextbtnbgdiv', function() {
$('.fyndspacecategory .nano-content').load('/get_session.php', '#session');
});
});
</script>
Or you could use a header within a page to access $_SESSION['cid'].
<?php
if ( isset( $_GET['get_session'] ) && $_GET['get_session'] ) {
header( 'X-Session: ' . $_SESSION['cid'] );
exit;
}
?>
<button class="btn nextbtnbgdiv open2" onclick="javascript:getSession();" type="button">Next <span class="fa fa-arrow-right"></span></button>
<div class="fyndspacecategory fyndsheightsubc nano">
<div class="nano-content" id="sessionId"><?php $cat_id= $_SESSION['cid']; ?></div>
</div>
<script>
function getSession() {
var request = new XMLHttpRequest();
request.onerror = function() { console.warn('An error occurred while checking session.'); };
request.open('HEAD', '?get_session=true', true);
request.onload = function() {
if ( request.getResponseHeader('X-Session') ) {
document.getElementById("sessionId").innerHTML = request.getResponseHeader('X-Session');
}
};
request.send();
}
</script>
This is not tested but should be enough to give you a start to complete your goal.
So my user's have access to changing their custom notify which is stored in my 'clients' database as 'notify'. I cannot seem to find out how to pull this information per session (as I don't want another user to change someone else's notify. Basically I'm trying to allow the user to click "Change Notify" in the navigation menu, then their notify (which I am guessing will depend on their session ID) shows up in the notify textbox, which will allow them to edit it accordingly.
This is my session starting php
<?php
include "includes/settings.php";
include "includes/database.php";
if(!isset($_SESSION))
{
session_start();
echo "Welcome=" . $_SESSION['id'];
}
if(!isset($_SESSION['username']))
{
echo'
<script language="javascript">
window.location.href="index.php"
</script>
';
}
$usersrow = mysqli_query($con, "SELECT COUNT(1) FROM `users`");
$user_row = mysqli_fetch_array($usersrow);
$user_total = $user_row[0];
$clients = mysqli_query($con, "SELECT COUNT(1) FROM `clients`");
$clients_row = mysqli_fetch_array($clients);
$clients_total = $clients_row[0];
$time_now = time("Y-m-d");
if(isset($_GET['deleteclient']))
{
if($_GET['deleteclient'])
{
$id = strip_tags($_GET['deleteclient']);
mysqli_query($con, "DELETE FROM `clients` WHERE `id` = '$id'") or die(mysqli_error($con));
}
}
?>
This is my update notify php
<?php
if(isset($_POST['upduser']))
{
$clientnotify = $_POST['notifyVal'];
$update_now = mysqli_query($con, "UPDATE `clients` SET `notify`='$clientnotify' WHERE `notify` = '".$client_notify."'");
if($update_now)
{
echo'<div class="row"><div class="col-md-12"><div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button>
<strong>OK!</strong> Client successfully updated!.
</div></div></div>';
echo '<meta http-equiv="refresh" content="1;url="dashboard.php">';
}
elseif(!$update_now)
{
echo'<div class="row"><div class="col-md-12"><div class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button>
<strong>Fail!</strong> Client not update, Try again!.
</div></div></div>
';
}
}
?>
This is my Custom Notify Form
<div class="panel panel-info">
<form method="POST">
<div class="panel-heading">
<h3 class="panel-title">SET CUSTOM NOTIFY</h3>
</div>
<div class="panel-body controls no-padding">
<div class="row-form">
<div class="col-md-3"><strong>Notify : </strong></div>
<div class="col-md-9"><input type="text" required class="form-control" value = "<?php echo $client_notify; ?>" placeholder="Notify" name="notifyVal"/></div>
</div>
</div>
<div class="panel-footer">
<button class="btn btn-success" name="updnotify">Set Custom Notify</button>
</div>
</form>
</div>
Any help would be appreciated.
I am trying to make a login for my website. Everything is working and I am currently logged in. Everytime I refresh the page the username and password will dissappear so my login will also dissappear. I do not want that to happen. So what can I do to keep the data in the scopes after a refresh? I get from my php a username password and a permission back and i set the loggedIn to true for my ng-show.
loginController.js
app.controller('loginController', ["$scope", "$http", function($scope, $http){
$scope.info = {
uname :'',
pass : ''
};
$scope.loggedIn = false;
$scope.name ={};
$scope.pass = {};
$scope.logout = function(loggedIn){
loggedIn=false;
};
$scope.users={};
$scope.logThatShitIn = function(info, name){
$http.post("php/userData.php",info)
.success(function(data){
$scope.name = data.user;
$scope.pass = data.pass;
$scope.loggedIn = 'true';
}
);
};
}]);
index.html -> my header
<body ng-controller='loginController'>
<div class="header">
<div class="headerName left">
<div class="headerNameText lname right">
lname
</div>
<div class="headerNameText fname right">
fname
</div>
</div>
<div class="nav left">
<ul>
<li class="navText">
<a ui-sref="dishes">Dishes</a>
</li>
<li class="navText">
<a ui-sref="addRecipe" ng-show='loggedIn'>Add Recipe</a>
</li>
</ul>
</div>
<div class="loginHeader right">
<div class="loginButton" ng-hide='loggedIn'>
<a ui-sref="login">log in</a>
</div>
<div class="logoutButton custFont" ng-show='loggedIn'>
<a href='#' ng-click='loggedIn = false'>log out</a>
</div>
<div class="loggedIn" ng-show='loggedIn'>
<p>welcome {{name}} !!</p>
</div>
</div>
login.html
<div>
<form name="login" ng-submit="logThatShitIn(info)">
<label>Username</label><br/>
<input type=text ng-model="info.uname" placeholder="Username"><br/><br/>
<label>Password</label><br/>
<input type="password" ng-model="info.pass" placeholder="Password"><br/><br/>
<input type='submit' value="Log in!"/>
</form>
<div ng-show='loggedIn'>
{{name}}
</div>
If you want the user to remain logged in after refreshing the page you will have to store their information on the client.
Try using $cookieStore to store their username and password in your log in function:
$cookieStore.put('username', name);
$cookieStore.put('password', pass);
Then you can retrieve the credentials and log in on a refresh in your app.run block. Put your login function into a loginService and inject it in app.run.
app.run(['loginService', function(loginService){
var username = $cookieStore.get('username');
var password = $cookieStore.get('password');
loginService.login(username, password);
}]);
documentation on $cookieStore