<div class="modal-header">
<a class="modal-close-med" data-dismiss="modal" aria-hidden="true"><img src="<?php echo base_url(); ?>img/close.png"></a>
<h3 class="modal-title no-margin margin-bottom-5p-min">Change Password</h3>
</div>
<div class="modal-body">
<?php if(isset($message))echo '<span class="text-success txt-upper" style="margin-left:2rem;">'. $message .'</span>';?>
<?php echo form_open('',array('class'=>'ajaxForm')); ?>
<fieldset class="table ">
<div class="form-group">
<?php $class = form_error('newpassword')?"input-error":"" ?>
<div class="col-md-12" style="margin: 10px 0"><?php echo form_password('newpassword','','class="form-control margin-both-0 '. $class.'" id="newpassword" placeholder="New Password" autocomplete="off"'); ?><?php echo form_error('newpassword'); ?></div>
</div>
<div class="form-group">
<?php $class = form_error('conpassword')?"input-error":"" ?>
<div class="col-md-12 " style="margin: 10px 0"><?php echo form_password('conpassword','','class="form-control margin-both-0 '. $class.'" id="conpassword" placeholder="Confirm Password" autocomplete="off"'); ?><?php echo form_error('conpassword'); ?></div>
</div>
</div>
<div class="modal-footer">
<form method="post" action="" id="myform">
<?php echo form_submit('submit_btn', 'Change Password', 'class="submit btn btn-success margin-left-4p pad-1-rem margin-bottom-10"'); ?>
</form>
</fieldset>
<?php echo form_close();?>
</div>
The Controller:
public function change_password ()
{
if($this->input->post('submit_btn')){
$this->session->set_flashdata('success','Password Changed Successfully');
redirect('dashboard');
}
// Set up the form
$rules = array(
'newpassword' => array(
'field' => 'newpassword',
'label' => 'New Password',
'rules' => 'trim|required|min_length[6]|xss_clean|check_pass'
),
'conpassword' => array(
'field' => 'conpassword',
'label' => 'Confirm Password',
'rules' => 'trim|required|min_length[6]|matches[newpassword]|xss_clean|check_pass'
),
);
$this->form_validation->set_rules($rules);
$this->form_validation->set_message('required', 'this field is required');
// Process the form
if ($this->form_validation->run() == TRUE) {
$password = $this->input->post("newpassword");
$userid = $this->session->userdata("id");
if($this->user_m->change_password($password, $userid)){
$this->data['message'] = 'password changed successfully';
//$this->data['subview'] = 'home/index';
//$this->load->view('_layout_main_1', $this->data);
}else{
$this->data['message'] = 'password must have at least one uppercase letter and a number';
}
$this->data['refresh'] = true;
}
// Load view
$this->load->view('home/change_password', $this->data);
}
This currently works when i click on change password button, however i want to make it work with the enter key. This is using Codeigniter and have tried to change it using standard html input type. but it did not work. Any help would be much appreciated
Wrap around with a form and the browser will handle this. Also use a submit button type:
<?php echo form_open('',array('class'=>'ajaxForm')); ?>
<div class="modal-header">
<a class="modal-close-med" data-dismiss="modal" aria-hidden="true"><img src="<?php echo base_url(); ?>img/close.png"></a>
<h3 class="modal-title no-margin margin-bottom-5p-min">Change Password</h3>
</div>
<div class="modal-body">
<?php if(isset($message))echo '<span class="text-success txt-upper" style="margin-left:2rem;">'. $message .'</span>';?>
<fieldset class="table ">
<div class="form-group">
<?php $class = form_error('newpassword')?"input-error":"" ?>
<div class="col-md-12" style="margin: 10px 0"><?php echo form_password('newpassword','','class="form-control margin-both-0 '. $class.'" id="newpassword" placeholder="New Password" autocomplete="off"'); ?><?php echo form_error('newpassword'); ?></div>
</div>
<div class="form-group">
<?php $class = form_error('conpassword')?"input-error":"" ?>
<div class="col-md-12 " style="margin: 10px 0"><?php echo form_password('conpassword','','class="form-control margin-both-0 '. $class.'" id="conpassword" placeholder="Confirm Password" autocomplete="off"'); ?><?php echo form_error('conpassword'); ?></div>
</div>
</fieldset>
</div>
<div class="modal-footer">
<?php echo form_submit('submit_btn', 'Change Password', 'class="submit btn btn-success margin-left-4p pad-1-rem margin-bottom-10"'); ?>
</div>
<?php echo form_close();?>
If you are using this for ajax request, you can disable to send the form itself, but enter still works:
<script>
$(function() {
$('.ajaxForm').on('submit', function(e) {
// ex.: $.post(...
console.log(e);
e.preventDefault();
})
})
</script>
Related
I have Two new fields here:
Its Number & Mauze but I am unable to see data in database:
The form gets submitted successfully but i cannot find the values of these two fields in my database
here's my code:
For form fields:
<div class="col-md-6">
<!-- custom text field -->
<label for='its' class="mycss1"><?php esc_html_e('ITS Number', 'masterstudy-lms-learning-management-system'); ?></label>
<input type="text"
name="its"
placeholder="Enter your ITS Number"
class="mycss"
kr-icon="fas fa-envelope"
required/>
</div>
<div class="col-md-6">
<!-- custom text field -->
<label for='mauze' class="mycss1"><?php esc_html_e('Enter your Mauze', 'masterstudy-lms-learning-management-system'); ?></label>
<input type="text"
name="mauze"
placeholder="Mauze"
class="mycss"
kr-icon="fas fa-envelope"
required/>
</div>`
for database connection:
<?php
if (isset($_POST['register'])) {
extract($_POST);
$servername = "localhost ";
$username = "root";
$password = "";
$dbname = "test";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO `wp_usermeta` (its,mauze)
VALUES ('$its','$mazue')";
if ($conn->query($sql) === TRUE) {
header('Location: register.php');
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
?>
Here's my full form data its an signup form
<?php
stm_lms_register_style('register');
enqueue_register_script();
$r_enabled = STM_LMS_Helpers::g_recaptcha_enabled();
$disable_instructor = STM_LMS_Options::get_option('register_as_instructor', false);
if ($r_enabled):
$recaptcha = STM_LMS_Helpers::g_recaptcha_keys();
endif;
$site_key = (!empty($recaptcha['public'])) ? $recaptcha['public'] : '';
if (class_exists('STM_LMS_Form_Builder')):
$additional_forms = STM_LMS_Form_Builder::register_form_fields();
$default_fields = STM_LMS_Form_Builder::profile_default_fields_for_register();
$register_form = $additional_forms['register'];
$become_instructor = $additional_forms['become_instructor'];
?>
<script>
window.profileDefaultFieldsForRegister = <?php echo sanitize_text_field(json_encode($default_fields)); ?>;
window.additionalRegisterFields = <?php echo sanitize_text_field(json_encode($register_form)); ?>;
window.additionalInstructorsFields = <?php echo sanitize_text_field(json_encode($become_instructor)); ?>;
</script>
<?php
endif;
?>
<div id="stm-lms-register"
class="vue_is_disabled"
v-init="site_key = '<?php echo stm_lms_filtered_output($site_key); ?>'"
v-bind:class="{'is_vue_loaded' : vue_loaded}">
<h3><?php esc_html_e('Sign Up', 'masterstudy-lms-learning-management-system'); ?></h3>
<form #submit.prevent="register()" class="stm_lms_register_wrapper">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="heading_font"><?php esc_html_e('Username', 'masterstudy-lms-learning-management-system'); ?></label>
<input class="form-control"
type="text"
name="login"
v-model="login"
placeholder="<?php esc_html_e('Enter username', 'masterstudy-lms-learning-management-system'); ?>"/>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="heading_font"><?php esc_html_e('E-mail', 'masterstudy-lms-learning-management-system'); ?></label>
<input class="form-control"
type="email"
name="email"
v-model="email"
placeholder="<?php esc_html_e('Enter your E-mail', 'masterstudy-lms-learning-management-system'); ?>"/>
</div>
</div>
<div class="col-md-6">
<!-- custom text field -->
<label for='its' class="mycss1"><?php esc_html_e('ITS Number', 'masterstudy-lms-learning-management-system'); ?></label>
<input type="text"
name="its"
placeholder="Enter your ITS Number"
class="mycss"
kr-icon="fas fa-envelope"
required/>
</div>
<div class="col-md-6">
<!-- custom text field -->
<label for='mauze' class="mycss1"><?php esc_html_e('Enter your Mauze', 'masterstudy-lms-learning-management-system'); ?></label>
<input type="text"
name="mauze"
placeholder="Mauze"
class="mycss"
kr-icon="fas fa-envelope"
required/>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="heading_font"><?php esc_html_e('Password', 'masterstudy-lms-learning-management-system'); ?></label>
<input class="form-control"
type="password"
name="password"
v-model="password"
placeholder="<?php esc_html_e('Enter password', 'masterstudy-lms-learning-management-system'); ?>"/>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="heading_font"><?php esc_html_e('Password again', 'masterstudy-lms-learning-management-system'); ?></label>
<input class="form-control"
type="password"
name="password_re"
v-model="password_re"
placeholder="<?php esc_html_e('Confirm password', 'masterstudy-lms-learning-management-system'); ?>"/>
</div>
</div>
<div v-for="(profileField, index) in profileDefaultFieldsForRegister" class="col-md-12">
<div class="form-group">
<label class="heading_font" v-html="profileField.label"></label>
<input class="form-control" v-if="index !== 'description'" type="text" v-model="profileField.value" :placeholder="profileField.placeholder" :required="profileField.required" />
<textarea class="form-control" v-if="index === 'description'" v-model="profileField.value" :placeholder="profileField.placeholder" :required="profileField.required"></textarea>
</div>
</div>
</div>
<div class="row additional-fields" v-if="additionalRegisterFields.length"
v-for="(field, index) in additionalRegisterFields">
<div class="col-md-12">
<div class="form-group">
<label class="heading_font" v-if="typeof field.label !== 'undefined'" v-html="field.label"></label>
<?php STM_LMS_Templates::show_lms_template('account/v1/form_builder/email'); ?>
<?php STM_LMS_Templates::show_lms_template('account/v1/form_builder/select'); ?>
<?php STM_LMS_Templates::show_lms_template('account/v1/form_builder/radio'); ?>
<?php STM_LMS_Templates::show_lms_template('account/v1/form_builder/textarea'); ?>
<?php STM_LMS_Templates::show_lms_template('account/v1/form_builder/checkbox'); ?>
<?php STM_LMS_Templates::show_lms_template('account/v1/form_builder/file', array('name' => 'register')); ?>
<div class="field-description" v-if="field.description" v-html="field.description"></div>
</div>
</div>
</div>
<transition name="slide-fade">
<div class="row" v-if="become_instructor && !additionalInstructorsFields.length">
<div class="col-md-6">
<div class="form-group">
<label class="heading_font"><?php esc_html_e('Degree', 'masterstudy-lms-learning-management-system'); ?></label>
<input class="form-control"
type="text"
name="degree"
v-model="degree"
placeholder="<?php esc_html_e('Enter Your Degree', 'masterstudy-lms-learning-management-system'); ?>"/>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="heading_font"><?php esc_html_e('Expertise', 'masterstudy-lms-learning-management-system'); ?></label>
<input class="form-control"
type="text"
name="expertize"
v-model="expertize"
placeholder="<?php esc_html_e('Enter your Expertize', 'masterstudy-lms-learning-management-system'); ?>"/>
</div>
</div>
</div>
</transition>
<div class="row additional-fields" v-if="become_instructor && additionalInstructorsFields.length"
v-for="(field, index) in additionalInstructorsFields">
<div class="col-md-12">
<div class="form-group">
<label class="heading_font" v-if="typeof field.label !== 'undefined'" v-html="field.label"></label>
<?php STM_LMS_Templates::show_lms_template('account/v1/form_builder/email'); ?>
<?php STM_LMS_Templates::show_lms_template('account/v1/form_builder/select'); ?>
<?php STM_LMS_Templates::show_lms_template('account/v1/form_builder/radio'); ?>
<?php STM_LMS_Templates::show_lms_template('account/v1/form_builder/textarea'); ?>
<?php STM_LMS_Templates::show_lms_template('account/v1/form_builder/checkbox'); ?>
<?php STM_LMS_Templates::show_lms_template('account/v1/form_builder/file', array('name' => 'becomeInstructor')); ?>
<div class="field-description" v-if="field.description" v-html="field.description"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<?php STM_LMS_Templates::show_lms_template('gdpr/privacy_policy'); ?>
<?php do_action('stm_lms_register_custom_fields'); ?>
<div class="stm_lms_register_wrapper__actions">
<?php ?>
<?php if (!$disable_instructor): ?>
<label class="stm_lms_styled_checkbox">
<span class="stm_lms_styled_checkbox__inner">
<input type="checkbox"
name="become_instructor"
v-model="become_instructor"/>
<span><i class="fa fa-check"></i> </span>
</span>
<span><?php esc_html_e('Register as Instructor', 'masterstudy-lms-learning-management-system'); ?></span>
</label>
<?php endif; ?>
<button type="submit"
class="btn btn-default"
:disabled="loading"
v-bind:class="{'loading': loading}">
<span><?php esc_html_e('Register', 'masterstudy-lms-learning-management-system'); ?></span>
</button>
</div>
</div>
</div>
</form>
<transition name="slide-fade">
<div class="stm-lms-message" v-bind:class="status" v-if="message">
{{ message }}
</div>
</transition>
</div>
<?php
if (isset($_POST['register'])) {
extract($_POST);
$servername = "localhost ";
$username = "root";
$password = "";
$dbname = "test";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO `wp_usermeta` (its,mauze)
VALUES ('$its','$mazue')";
if ($conn->query($sql) === TRUE) {
header('Location: register.php');
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
?>
Update: After someone suggested in comments it's working now. I am still not able to work the login/logout button that's in index.php file. When I log in it does verify the password, but does not show the logout button. It shows the error in index.php (I have commented out the line) it says undefined index name Any help is appreicated.
I have a signup and login form in my website. I am able to signup properly and I am storing the password as hashed. When I try to login it keep saying wrong password. I am assuming there might be something wrong with my code since the password I am typing is correct.
index.php
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors', '1');
require "navigationbar.php";
require "loginpage.php";
?>
<html>
<head>
<link href="https://fonts.googleapis.com/css2?family=Dancing+Script&display=swap" rel="stylesheet">
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
<link href="stylee.css" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css2?family=Raleway:wght#100&display=swap" rel="stylesheet">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</head>
<body>
<?php
$user = $_SESSION['name'] ; //it says undefined index name
if (isset($user )) {
echo '<p>You are logged in</p>';
echo '<form action="logout.php" method="post">
<button type="submit" name="logout-submit">Logout</button>
</form>';
<link href="stylee.css" rel="stylesheet" />
<form action="logoutbackend.php" method="post">
<button type="submit" name="logout-submit" class="logout_button">Logout</button>
</form>';
} else {
echo '<p class="login-status">You are logged out!</p>';
echo '<div class="login-container">
<form action="./backend/loginbackend.php" method="post">
<div class="form-group row">
<div class="col-sm-10">
<h2>website</h2>
</div>
</div>
<div class="form-group row">
<div class="col-sm-10">
<input type="email" class="form-control" name="email" placeholder="Email">
</div>
</div>
<div class="form-group row">
<div class="col-sm-10" >
<input type="password" class="form-control" name="password" placeholder="password">
</div>
</div>
<div class="form-group row">
<div class="col-sm-10">
<button type="submit" class="btn btn-primary" name="login_submit">Log In</button>
</div>
</div>
</form>
<div class="form-group row">
<div class="col-sm-10">
<p>New to <span>ShowCo</span>?<a class="open-button" onclick="openForm()">Sign up</a> </p>
</div>
</div>
<div class="form-popup" id="myForm">
<form action="./backend/signupbackend.php" class="form-container" method="post">
<div class="form-group row">
<div class="col-sm-10" >
<h1>Sign up</h1>
</div>
</div>
<div class="form-group row">
<div class="col-sm-10" >
<input type="text" class="form-control" placeholder="Username" name="username" required>
</div>
</div>
<div class="form-group row">
<div class="col-sm-10" >
<input type="email"class="form-control" placeholder="Email address" name="mail" required>
</div>
</div>
<div class="form-group row">
<div class="col-sm-10" >
<input type="password" class="form-control" placeholder="Password" name="password" required>
</div>
</div>
<div class="form-group row">
<div class="col-sm-10" >
<input type="password" class="form-control" placeholder="Repeat password" name="repeatpassword" required>
</div>
</div>
<div class="form-group row">
<div class="col-sm-10" >
<button type="submit" class="btn btn-primary" name="signup_submit">Sign up</button>
</div>
</div>
<button type="button" class="close" aria-label="Close" onclick="closeForm()"><span aria-hidden="true">×</span></button>
</form>
</div>
</div>
<script>
function openForm() {
document.getElementById("myForm").style.display = "block";
}
function closeForm() {
document.getElementById("myForm").style.display = "none";
}
</script>
';
}
?>
</body>
</html>
<?php
require "footer.php";
?>
Signupbackend.php
<?php
if(isset($_POST["signup_submit"])) {
require "../database_files/database_for_signup.php";
require "../index.php";
$username = $_POST['username'];
$email = $_POST['mail'];
$password = $_POST['password'];
$repeatPassword = $_POST['repeatpassword'];
if (empty($username) || empty($email) || empty($password) || empty($repeatPassword)) {
header("Location: ../index.php?error=emptyfields&username=" .$username."&mail=" .$email);
exit();
} else if(!filter_var($email, FILTER_VALIDATE_EMAIL) && !preg_match("/^[a-zA-Z0-9]*$/",$username)) {
header("Location: ../index.php?error=invalidmailusername");
exit();
} else if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
header("Location: ../index.php?error=invalidmail&username=".$username);
exit();
} else if (!preg_match("/^[a-zA-Z0-9]*$/",$username)) {
header("Location: ../index.php?error=invalidusername&mail=".$email);
exit();
} else if($password != $repeatPassword) {
header("Location: ../index.php?error=passwordcheck&username=".$username."&mail=".$email);
exit();
} else {
$sql = "SELECT COUNT(username) AS num FROM signup_info WHERE username = :username";
$stmt = $conn->prepare($sql);
$stmt->bindValue(':username', $username);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($row['num'] > 0) {
die('Sorry, username already exists. Please try a different username');
}
$passwordHash = password_hash($pass, PASSWORD_BCRYPT, array("cost" => 12));
$sql = "INSERT INTO signup_info(username, email, password) VALUES (:username, :email, :password)";
$stmt = $conn->prepare($sql);
$stmt->bindValue(':username', $username);
$stmt->bindValue(':email', $email);
$stmt->bindValue(':password', $passwordHash);
$result = $stmt->execute();
if($result) {
echo "Registered!";
}
}
}
?>
Loginbackend.php
<?php
if(isset($_POST['login_submit'])) {
require "../database_files/database_for_signup.php";
$email = $_POST['email'];
$password = $_POST['password'];
if ((empty($username)) || (empty($password))) {
echo 'empty username/password';
die();
}
$sql = 'SELECT username, email, password FROM signup_info WHERE email = :email';
if ($stmt = $conn->prepare($sql)) {
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
if ($stmt->execute()) {
if($stmt->rowCount() == 1) {
if ($row = $stmt->fetch()) {
$hashed_password = $row['password'];
if(password_verify($password, $hashed_password)) {
session_start();
$_SESSION['email'] = $email;
$_SESSION['name'] = $row['username'];
echo "verfiied";
} else {
echo "wrong password"; }
}
}
}
}
}
?>
logout.php
<?php
session_start();
session_unset();
session_destroy();
header("Location: ./index.php");
Please help me why I am not able to verify the password? Also, I have been through similar questions on SO, but nothing helped. Any help is appreciated.
I am using Laravel, I have a following data view
<div class="content-inside-main">
<div class="content-inside" id="content-inside-feedback">
<div class="row header-content space-div">
<div class="col-lg-1"><h5>#</h5></div>
<div class="col-lg-1"><h5>Member Id</h5></div>
<div class="col-lg-4"><h5>Question</h5></div>
<div class="col-lg-4"><h5>Reply</h5></div>
<div class="col-lg-1"><h5>Replied by</h5></div>
<div class="col-lg-1"><h5>Options</h5></div>
</div>
<div>
<hr class="line-div"/>
</div>
<?php
$questions= \App\Question::all();
?>
<?php
foreach ($questions as $question):
$id = $question->id;
$member_id = $question->user_id;
$body = $question->message;
$status=$question->replied;
$reply=$question->reply;
$user_id=$question->replied_id;
$member=\App\Member::find($member_id);
$m_id=$member->id;
$m_name=$member->nick_name;
$m_reg_time=$member->reg_time;
$m_unreg_time=$member->unreg_time;
$m_status=$member->unreg;
$m_group_id=$member->group;
$group=\App\Group::find($m_group_id);
$m_group_name=$group->name;
if($id != NULL) {
?>
<div class="row content-messages" >
<input type="hidden" id="count" value="{{$id}}"/>
<div class="col-lg-1"><?php echo $id; ?></div>
<div class="col-lg-1"><?php echo $member_id; ?></div>
<div class="col-lg-4"><?php echo $body; ?></div>
<div class="col-lg-4">
<?php
if($status == 0){
?>
<div class="according-form-container" id="reply-feedback-form_<?php echo $id; ?>">
<a class="btn-link show-add-form-div" data-toggle="collapse" data-parent="#reply-feedback-form_<?php echo $id; ?>" href="#reply-feedback-form_content_<?php echo $id; ?>" >
Reply
</a>
<div id="reply-feedback-form_content_<?php echo $id; ?>" class="collapse collapse-add-form">
<form class="form" id="reply-feedback_<?php echo $id; ?>" enctype="multipart/form-data" method="post" action="addreply">
{{csrf_field()}}
<div class="control-group">
<label class="control-label" for="description">Message: </label>
<div class="controls">
<input type="hidden" name="id" id="id" value="{{$id}}"/>
<input type="hidden" name="member_id" id="member_id" value="{{$member_id}}"/>
<input type="hidden" name="user_id" id="user_id" value="{{Auth::id()}}"/>
<textarea name="description" id="feedback-message_<?php echo $id; ?>" class="input-block-level" required></textarea>
<br/><br/>
<button id="submitfeedback_<?php echo $id . '_' . $member_id; ?>" type="submit" class="btn feedback-reply-submit-btn">Send</button>
</div>
</div>
</form>
<div id='preview_feedback_<?php echo $id; ?>'>
</div>
</div>
</div>
<?php
} else {?>
<div class="col-lg-4">{{$reply}}</div>
<?php
}
?>
</div>
<div class="col-lg-1">
<?php
if($user_id != null){
$user_name= DB::table('admin')->where('id',$user_id)->value('name');
echo $user_name;
}else {
echo 'None';
}
?>
</div>
<div class="col-lg-1">
<button id="view_member" name="view_member" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#view_memeber"
>View
</button>
</div>
</div>
<hr class="line-div" />
<?php
}
endforeach;
?>
<div id="show"></div>
<div class="text-center navigation-paginator" id="paginator" >
</div>
</div>
I have another application.It fill question table anytime.I want to do If question table have new records,show them in this page without refreshing.
Like following screenshots:
before
after
You could send periodical ajax calls and then compare the results with the data you already have to add the new values. It could be something along this lines:
function query() {
$.ajax({
url: 'your/url',
success: function(data) {
var loadedValues = JSON.parse(data).values;
// Iterate only in the new values
for(i = existingValues.length; i < loadedValues.length; i++) {
$("#content-inside-feedback").append(/*HTML you want to add*/);
}
}
});
setTimeout(executeQuery, 5000);
}
$(document).ready(function() {
// First call, then it will be called periodically
setTimeout(query, 5000);
});
Just want to ask on how to get the ID in a specific foreach
My Controller
public function validate_subtopic(){
$data = array('success' => false, 'messages' => array());
$this->form_validation->set_rules("subtopicname", "SubTopicName", "trim|required");
$this->form_validation->set_rules("subtopicdescription", "SubTopicDescription", "trim|required");
$this->form_validation->set_error_delimiters('<p class="text-danger">', '</p>');
if($this->form_validation->run()){
$data['success'] = true;
$subtopic_data = array(
'subtopicname' => $this->input->post('subtopicname'),
'subtopicdescript' => $this->input->post('subtopicdescription'),
'subjectID' => $this->input->post('subjectID'),
'topicID' => $this->input->post('topicID'),
);
$this->addtopic_model->insert_subtopic($subtopic_data);
}
else{
foreach ($_POST as $key => $value) {
$data['messages'][$key] = form_error($key);
}
}
echo json_encode($data);
}
My Model
public function insert_subtopic($subtopic_data){
$this->db->insert('subtopics', $subtopic_data);
}
My view from bootstrap modal
<div class="modal inmodal fade" id="addSubTopic" tabindex="-1" role="dialog" aria-hidden="true">
<?php
$att = array(
'method' => 'POST',
'id' => "form-user_sub");
echo form_open("topicAdd_Controller/validate_subtopic", $att);
?>
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h5 class="modal-title">Please Input SubTopic</h5>
</div>
<div id="the-message"></div>
<div class="modal-body">
<form role="form">
<div class="form-group">
<label>Sub Topic Name</label>
<input class="form-control" name="subtopicname" id="subtopicname" type="text">
</div>
<div class="form-group">
<label>Sub Topic Description</label>
<textarea name="subtopicdescription" id="subtopicdescription" class="form-control">
</textarea>
</div>
<?php foreach($sample as $row){
?>
<?php $index = current($sample); ?>
<input type="text" value="<?php echo $row['topicID']; ?> name="topicID">
<?php } ?>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save</button>
</div>
</div>
</div>
<?php form_close();?>
</div>
This is the output of $sample:
The problem is I can't get the ID from the specific foreach loop I choose. how can I solve this?
Please help
You can use while(){} method, so your script will be like this
$i = 0;
$res = array();
while($data = $_POST){
$res[$i] = $data;
$i++;
}
echo json_encode($res);
I have been working on a ban management system for a little bit but I encountered a error with the login system where it does not work
Live example:
http://lotus.pe.hu/lbans/index.php/
username: admin
pass: anmol123
Their is no error or anything with the code from where I can tell if you need the code I will post it
index.php
<html>
<head>
<link rel="stylesheet" href="css/bootstrap.min.css"/>
<title>LotusBans [BETA] [V 1.0] ~ Home</title>
</head>
<body>
<?php
require("api/api.php");
require("header.php");
?>
<div class="jumbotron">
<div class="container">
<h2>LotusBans [BETA] [v1.0]</h2>
<p>View the players banned on the LotusNetwork Here</p>
</div>
</div>
<?php if (isset($_SESSION["username"])) { ?>
<div class="container">
<input type="button" value="+" data-toggle="modal" data-target="#modal" class="btn btn-primary pull-right"/>
<br/><br/>
</div>
<?php } ?>
<div class="container">
<table class="table table-bordered">
<tr>
<th>ID</th>
<th>UUID</th>
<th>Date</th>
<th>Reason</th>
</tr>
<?php
$bans = get_bans();
while ($ban = $bans->fetch_assoc()) {
?>
<tr>
<td><?php echo $ban["id"] ?></td>
<td><?php echo $ban["uuid"] ?></td>
<td><?php echo $ban["date"] ?></td>
<td><?php echo $ban["reason"] ?></td>
</tr>
<?php } ?>
</table>
</div>
<div class="modal fade" id="modal" tabindex="-1" role="dialog">
<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">Add Ban</h4>
</div>
<form id="form">
<div class="modal-body">
<div class="form-group">
<input type="text" id="uuid" name="uuid" placeholder="UUID" class="form-control"/>
</div>
<div class="form-group">
<input type="text" id="reason" name="reason" placeholder="Reason" class="form-control"/>
</div>
</div>
<div class="modal-footer">
<input type="submit" class="btn btn-primary"/>
</div>
</form>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script>
$(document).ready(function() {
$("#form").submit(function(e) {
e.preventDefault();
var uuid = $("#uuid").val();
var reason = $("#reason").val();
$.post("api/add.php", { uuid: uuid, reason: reason }, function(data) {
location.href = "ban.php?id=" + data;
});
});
});
</script>
</body>
header.php
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">LotusBans</a>
</div>
<?php session_start(); if (!isset($_SESSION["username"])) { ?>
<form method="post" action="login.php" class="navbar-form navbar-right">
<div class="form-group">
<input type="text" name="username" placeholder="Username" class="form-control">
<input type="password" name="password" placeholder="Password" class="form-control">
</div>
<button type="submit" class="btn btn-primary">Log In</button>
</form>
<?php } else { ?>
<div class="navbar-right">
<p class="navbar-text">Welcome, <?php echo $_SESSION["username"]; ?></p>
</div>
<?php } ?>
</div><!-- /.container-fluid -->
api.php
<?php
define("key", file_get_contents("http://lotus.pe.hu/lbans/can'tenterthis as this is a key"));
function get_mysql() {
$mysql = new mysqli("", "", "", "");
if ($mysql->connect_error) {
die($mysql->connect_error);
}
return $mysql;
}
function add($uuid, $reason) {
$date = date("Y-m-d H:i:s");
get_mysql()->query("insert into bans (uuid, date, reason) values ('$uuid', '$date', '$reason')");
return get_mysql()->query("select id from bans where uuid = '$uuid' and date = '$date' and reason = '$reason'")->fetch_assoc()["id"];
}
function update($id, $uuid, $reason) {
get_mysql()->query("update bans set uuid = '$uuid', reason = '$reason' where id = $id");
}
function remove($uuid) {
get_mysql()->query("delete from bans where uuid = '$uuid'");
}
function remove_by_id($id) {
get_mysql()->query("delete from bans where id = $id");
}
function get($uuid) {
return get_mysql()->query("select * from bans where uuid = '$uuid'")->fetch_assoc();
}
function get_by_id($id) {
return get_mysql()->query("select * from bans where id = $id")->fetch_assoc();
}
function get_bans() {
return get_mysql()->query("select * from bans");
}
function login($username, $password) {
$password = hash("sha256", $password);
return get_mysql()->query("select count(*) from users where username = '$username' and password = '$password'")->fetch_assoc()["count(*)"] > 0;
}
function register($username, $password) {
$password = hash("sha256", $password);
get_mysql()->query("insert into users (username, password) values ('$username', '$password')");
}
?>
Try to add this to this..
<?php
session_start(); //Transfer the session_start() here ..
require("api/api.php");
if( isset($_POST['username']) )
{
if( login( $_POST['username'], $_POST['password'] ) )
{
$_SESSION['username'] = $_POST['username'];
}
else
{
echo 'Invalid username/password';
}
}
require("header.php");
?>