How to call a PHP function from a different page? - php

This is the USER class with the register and send_mail functions. The send_mail function doesn't work. I've followed other questions that were similar, but it doesn't work for me. Maybe someone can spot a mistake I've made, thanks.
require_once 'dbconfig.php';
class USER
{
public function register($uname,$email,$upass,$code)
{
try
{
$password = md5($upass);
$stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass,tokenCode)
VALUES(:user_name, :user_mail, :user_pass,
:active_code)");
$stmt->bindparam(":user_name",$uname);
$stmt->bindparam(":user_mail",$email);
$stmt->bindparam(":user_pass",$password);
$stmt->bindparam(":active_code",$code);
$stmt->execute();
return $stmt;
}
catch(PDOException $ex)
{
echo $ex->getMessage();
}
}
function send_mail($email,$message,$subject)
{
require_once('mailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "mail.smeinfratech.co.za";
$mail->Port = 465;
$mail->AddAddress($email);
$mail->Username="datalogging#smeinfratech.co.za";
$mail->Password="**********";
$mail->SetFrom('datalogging#smeinfratech.co.za','SME DATALOGGING');
$mail->AddReplyTo("datalogging#smeinfratech.co.za","SME DATALOGGING");
$mail->Subject = $subject;
$mail->MsgHTML($message);
$mail->isHTML(true);
$mail->Send();
}
}
The following is the sign up page code where call these functions
<?php
if(!session_id()){
session_start();
}
require_once 'class.user.php';
require_once 'dbconfig.php';
$reg_user = new USER();
if ($reg_user->is_logged_in() != "") {
$reg_user->redirect('SystemStatus.php');
}
Post for the submit button
if (isset($_POST['btn-signup'])) {
$uname = ($_POST['txtuname']);
$email = ($_POST['txtemail']);
$upass = ($_POST['txtpass']);
$code = md5(uniqid(rand()));
$stmt = $reg_user->runQuery("SELECT * FROM tbl_users WHERE userEmail=:email_id");
$stmt->execute(array(
":email_id" => $email
));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($stmt->rowCount() > 0) {
$msg = "<div class='alert alert-danger'>
<strong>Sorry!</strong> The email already exists. Please try another one.
</div>";
}
else
{
$reg_user->register($uname, $email, $upass, $code);
$id = $reg_user->lasdID();
$key = base64_encode($id);
$id = $key;
$message = "<div class='alert alert-success'>
Hello $uname,
<br /><br />
Welcome to SME Datalogging!<br/>
To complete your registration please click the following link<br/>
<br /><br />
<a href='http://elec.specmech.co.za/SMELogin2/verify.php?id=$id&code=$code'>Click HERE to Activate :)</a>
<br /><br />
Thanks,
</div>";
$subject = "Confirm Registration";
send_mail($email, $message, $subject);
$msg = "<div class='alert alert-success'>
<strong>Success!</strong> We've sent an email to $email.
Please click on the confirmation link in the email to create your account.
</div>";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>SME DATALOGGING | Sign Up</title>
<?php require_once 'v2/php/head.php'; ?>
</head>
<body>
<div id="content" class="container pt-5">
<div class="row">
<div class="col-md-6 offset-md-3">
<div class="system-card">
<img src="v2/img/sme.png" alt="SME" width="100%"/>
<form>
<div class="text-center">
<h4 class="mb-5 mt-5 text-primary"><strong>Sign Up</strong></h4>
</div>
<div class=" form-sm mt-5">
<label class="required">Username</label>
<input type="text" id="username" class="form-control" formControlName="username" name="txtuname" required>
</div>
<div class=" form-sm">
<label class="required">Email</label>
<input type="text" id="email" class="form-control" formControlName="email" name="txtemail" required>
</div>
<div class=" form-sm">
<label class="required">Password</label>
<input type="password" id="password" class="form-control" formControlName="password" name="txtpass" required>
</div>
<div class="row d-flex align-items-center mb-4 mt-4">
<div class="col-md-3 col-md-6 text-center">
<button class="btn btn-primary btn-block" type="submit" name="btn-signup">SIGN UP</button>
</div>
<div class="col-md-6">
<div class="text-center">
<small>
Already have an acount? Sign In
</small>
</div>
</div>
</div>
<?php
if (isset($msg)) echo $msg;
?>
</form>
</div>
</div>
</div>
</div>
<script src="vendors/jquery-1.9.1.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="/assets/js/jquery-2.1.4.min.js"></script>
</body>
</html>

From what I can see you are trying to call the send_mail method of the USER class as a regular function.
$subject = "Confirm Registration";
send_mail($email, $message, $subject);
This is not going to work, because there is no function named send_mail.
You will have to create an instance of the class USER, and then call the method send_mail.
$subject = "Confirm Registration";
$user = new USER;
$user->send_mail($email, $message, $subject);
This is how you would call this method.
Or just like this (given that $reg_user is an instance of the USER class).
$subject = "Confirm Registration";
$reg_user->send_mail($email, $message, $subject);

Related

Cannot display alert once the user login inputs incorrect credentials PHP PDO

index.php
This is the login form
<div class="modal-body">
<form action="loginPDO.php" method="post">
<?php if(isset($message))
{
echo '<label class="text-danger">'.$message.'</label>';
} ?>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Username:</label>
<input type="text" name="username" id="username" placeholder="Enter Username" class="form-control">
</div>
<div class="form-group">
<label for="message-text" class="col-form-label">Password:</label>
<input type="password" name="password" id="password" placeholder="Enter Password" class="form-control">
</div>
<div class="form-group">
<button type="submit" name="login" id="login" class="btn btn-primary">Login</button>
<button type="button" class="btn btn-info">Register</button>
</div>
</form>
</div>
loginPDO.php
<?php
include 'dbconnection.php';
if(isset($_POST["login"]))
{
if(empty($_POST["username"]) || empty($_POST["password"]))
{
$message = '<label>All fields are required</label>';
header("location:index.php");
}
else
{
$query = "SELECT * FROM users WHERE username = :username AND password = :password";
$statement = $conn->prepare($query);
$statement->execute(
array(
'username' => $_POST["username"],
'password' => $_POST["password"]
)
);
$count = $statement->rowCount();
if($count > 0)
{
$_SESSION["username"] = $_POST["username"];
header("location:dashboard.php");
}
else
{
$message = '<label>Wrong Data</label>';
header("location:index.php");
}
}
}
?>
Hi Guys, I want to know how to display the alert message once the user inputs incorrect credentials
For example, Imagine the user inputs wrong credentials once the user clicks the login button it automatically appears the alert message above Username.
$message just exists in file loginPDO.php and ...
$message = '<label>Wrong Data</label>';
header("location:index.php");
Is not sufficient to pass the $message variable to index.php.
As said in comments you can try
// file loginPDO.php
$message = '<label>Wrong Data</label>';
header("location:index.php?error=" . urlencode("Wrong Data"));
// file index.php
<?php
$message = isset($_GET['error']) ? $_GET['error'] : null; // get the error from the url
if(!empty($message)) {
echo '<label class="text-danger">'.$message.'</label>';
} ?>

Query not working on PostgreSQL database

I have a query where I check if a user it's already stored on the database, but the problem it's that it's perfectly working on MYSQL but not on PostgreSQL where I need it..what can I do? The steps are: user register for an account. If it already exists in the database it returns an message, if no, send an email where he needs to confirm the registration. The confirmation doesn't work(the adress where the user can enter and activate his account).
This is the confirmation code(email_verification.php):
<?php
ob_start();
$success = false;
// Errors reporting, used if needed
error_reporting(E_ALL);
ini_set('display_errors', 'on');
// General configuration like base, used if needed
include_once ('include/config.inc.php');
// Mail functions
include_once ('include/mail.functions.php');
// Start session if needed
session_start();
// DBConn
include_once ('class/DB/DBConn.includeall.php');
$db = new DBConn(NULL);
// Includere clasa login
require_once ('class/class_login.php');
// Set up current language
$lang = "ro";
$_SESSION[PRE.'lang'] = $lang;
$message = '';
if(isset($_GET['cod_activare']))
{
$query = "
SELECT * FROM tregister
WHERE cod_activare = :cod_activare
";
$statement = $connect->prepare($query);
$statement->execute(
array(
':cod_activare' => $_GET['cod_activare']
)
);
$no_of_row = $statement->rowCount();
if($no_of_row > 0)
{
$result = $statement->fetchAll();
foreach($result as $row)
{
if($row['email_status'] == '0')
{
$update_query = "
UPDATE tregister
SET email_status = '1'
WHERE id = '".$row['id']."'
";
$statement = $connect->prepare($update_query);
$statement->execute();
$sub_result = $statement->fetchAll();
if(isset($sub_result))
{
$message = '<label class="text-success">Email verificat cu success! <br />Poti efectua checkin-ul aici - Efectueaza check-in</label>';
}
}
else
{
$message = '<label class="text-info">Adresa de mail deja verificata</label>';
}
}
}
else
{
$message = '<label class="text-danger">Link invalid</label>';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Hotel Amethyst</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<h3><?php echo $message; ?></h3>
</div>
</body>
</html>
<?php
ob_end_flush();
?>
And here it's the register.php:
<?php
ob_start();
$success = false;
// Errors reporting, used if needed
error_reporting(E_ALL);
ini_set('display_errors', 'on');
// General configuration like base, used if needed
include_once ('include/config.inc.php');
// Mail functions
include_once ('include/mail.functions.php');
// Start session if needed
session_start();
// DBConn
include_once ('class/DB/DBConn.includeall.php');
$db = new DBConn(NULL);
// Includere clasa login
require_once ('class/class_login.php');
// Set up current language
$lang = "ro";
$_SESSION[PRE.'lang'] = $lang;
$access = 0;
// Check if the cookie for "remember me" exists
if(isset($cookie_name))
{
if(isset($_COOKIE[$cookie_name]))
{
parse_str($_COOKIE[$cookie_name]);
$login = new Login($db);
if ($login->_checkLogin($usr, $hash) == true)
{
$access = 1;
}
}
}
$user = (isset($_POST['user']) && !empty($_POST['user'])) ? $_POST['user'] : "" ;
$email = (isset($_POST['email']) && !empty($_POST['email'])) ? $_POST['email'] : "" ;
$cod_activare = md5(rand());
$email_status=0;
$db = pg_connect("host=local port=5432 dbname=login_robinson user=robinson password=123");
$query = "INSERT INTO tregister(nume,email,cod_activare,email_status) VALUES ('$user','$email','$cod_activare','$email_status')";
$result = pg_query($query);
if(isset($_POST['submit'])){
$base_url = "http://local/login-robinson/www/";
$mail_body = "
Buna ziua ".$_POST['user'].",\n
Multumim pentru inregistrare. Te rog deschide acest link pentru a incepe procesul de check-in - ".$base_url."email_verification.php?activation_code=".$cod_activare."
Cu stima,\nHotel Amethyst
";
$from = 'Activare rezervare';
$subject = 'De pe site';
if (mail ($email, $subject, $mail_body, $from)){
echo "<script>
alert('Utilizator inregistrat cu success! Te rog verifica adresa de mail!');
window.location.href='login.php';
</script>";
}
else{
echo "<script>
alert('S-a produs o eroare! Te rog mai verifica odata formularul!');
</script>";
}
if($user !=''&& $email !='')
{
$success=true;
}
}
?>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<!-- <base href="http://dev.incorom.local/ticketing/www/login.php" /> -->
<title>Inregistrare</title>
<?php
include('include/links.php');
include('include/scripts.php');
?>
</head>
<body style="display: block !important;" ng-cloak="" ng-class="{ 'layout-fixed' : app.layout.isFixed, 'layout-boxed' : app.layout.isBoxed, 'layout-dock' : app.layout.isDocked, 'layout-material': app.layout.isMaterial, 'aside-offscreen' : app.sidebar.isOffscreen, 'aside-mini' : app.sidebar.isMini, 'aside-right' : app.sidebar.isRight, 'footer-hidden': app.footer.hidden, 'in-app': !$state.includes('page')}">
<div class="animated fadeOutZoom">
<div class="container container-sm animated fadeInDown">
<div class="center-block mt-xl">
<img src="images/logo_iconlab.png" alt="Image" class="center-block img-rounded">
<div class="panel">
<div class="panel-body">
<p class="pv text-bold">Date de inregistrare rezervare</p>
<form class="mb-lg" method="post" action="register.php" id="form">
<div class="row">
<div class="col-md-12">
<div class="form-group has-feedback mb">
<input type="text" placeholder="Nume" autocomplete="off" class="form-control" name="user" id="user" required /><span class="fa fa-envelope form-control-feedback text-muted"/></span>
</div><br>
<div class="form-group has-feedback mb">
<input type="email" placeholder="Adresa de mail" autocomplete="off" class="form-control" name="email" id="email" required /><span class="fa fa-envelope form-control-feedback text-muted"/></span>
</div><br>
</div>
<div class="col-md-12">
<button type="submit" class="btn btn-block btn-info btnblue mb" name="submit">Inregistrare</button>
</div>
</div>
<div id="main_area" class="row-fluid">
</form>
</div>
</div>
</div>
</div>
</body>
</html>
<?php
ob_end_flush();
?>
The registration works OK but I can register the same email for an infinite number of times.

Form validation is not working in my CI project (fixed, code updated)

I am newbie at CodeIgniter. I am trying to implement form validation in user registration.
$autoload['libraries'] = array('database','session','encrypt','form_validation');
$autoload['helper'] = array('url','file','form');
$autoload['model'] = array('user_model');
Controller's Code:
class User_registration extends CI_Controller {
public function index() {
$this->register();
}
function register() {
//set validation rules
$this->load->library('form_validation');
$this->form_validation->set_rules('user_name', 'First Name', 'trim|required|alpha|min_length[3]|max_length[30]|xss_clean');
$this->form_validation->set_rules('email_id', 'Email ID', 'trim|required|valid_email|is_unique[email_id]');
$this->form_validation->set_rules('user_password', 'Password', 'trim|required|matches[confirm_password]|md5');
$this->form_validation->set_rules('confirm_password', 'Confirm Password', 'trim|required|md5');
//validate form input
if ($this->form_validation->run() == FALSE) {
// fails
$data = array();
$data['title'] = 'Registration | Admin Panel';
$data['header_content'] = $this->load->view('adminEntry/header_content', '', true);
$data['footer_content'] = $this->load->view('adminEntry/footer_content', '', true);
$this->load->view('adminentry/user_registration', $data);
} else {
//insert the user registration details into database
echo '<pre>';
print_r($data);
exit();
$data = array(
'user_name' => $this->input->post('user_name'),
'email_id' => $this->input->post('email_id'),
'password' => $this->input->post('user_password'),
);
if ($this->user_model->insertuser($data)) {
if ($this->user_model->sendEmail($this->input->post('email_id'))) {
// successfully sent mail
$this->session->set_flashdata('msg', '<div class="alert alert-success text-center">You are Successfully Registered! Please confirm the mail sent to your Email-ID!!!</div>');
redirect('user_registration');
} else {
// error
$this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Oops! Error. Please try again later!!!</div>');
redirect('user_registration');
}
} else {
// error
$this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Oops! Error. Please try again later!!!</div>');
redirect('user_registration');
}
}
}
User Model:
class User_model extends CI_Model {
//insert into user table
function insertUser($data) {
return $this->db->insert('user', $data);
}
function sendEmail($to_email) {
$from_email = 'sample#mail.com'; //change this to yours
$subject = 'Verify Your Email Address';
$message = 'Dear User,<br /><br />Please click on the below activation link to verify your email address.<br /><br /> http://example.com/user/verify/' . md5($to_email) . '<br /><br /><br />Thanks<br />Mydomain Team';
//configure email settings
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.example.com'; //smtp host name
$config['smtp_port'] = '465'; //smtp port number
$config['smtp_user'] = $from_email;
$config['smtp_pass'] = 'examplepass'; //$from_email password
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes
$this->email->initialize($config);
//send mail
$this->email->from($from_email, 'example.com');
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($message);
return $this->email->send();
}
//activate user account
function verifyEmailID($key) {
$data = array('approval_status' => 1);
$this->db->where('md5(email_id)', $key);
return $this->db->update('user', $data);
}
}
View Page:
<div class="container">
<div class="full-content-center animated fadeInDownBig">
<p class="text-center"><img src="<?php echo base_url(); ?>adminAssets/img/login-logo.png" alt="Logo"></p>
<div class="login-wrap">
<div class="row">
<div class="col-sm-6">
<?php echo $this->session->flashdata('verify_msg'); ?>
</div>
</div>
</div>
<div class="login-block">
<?php
$attributes = array("name" => "registrationform");
echo form_open("user_registration/index", $attributes);
?>
<form role="form" method="post" action="<?php echo base_url(); ?>user_registration" enctype="multipart/form-data>">
<div class="form-group login-input">
<i class="fa fa-user overlay"></i>
<input type="text" name="user_name" value="<?php echo set_value('user_name'); ?>" class="form-control text-input" placeholder="Name">
<span class="text-danger"><?php echo form_error('user_name'); ?></span>
</div>
<div class="form-group login-input">
<i class="fa fa-envelope overlay"></i>
<input type="text" name="email_id" value="<?php echo set_value('email_id'); ?>" class="form-control text-input" placeholder="E-mail">
<span class="text-danger"><?php echo form_error('email_id'); ?></span>
</div>
<div class="form-group login-input">
<i class="fa fa-key overlay"></i>
<input type="password" name="user_password" value="<?php echo set_value('user_password'); ?>" class="form-control text-input" placeholder="Password" id="txtNewPassword">
<span class="text-danger"><?php echo form_error('user_password'); ?></span>
</div>
<div class="form-group login-input">
<i class="fa fa-key overlay"></i>
<input type="password" name="confirm_password" value="<?php echo set_value('confirm_password'); ?>" class="form-control text-input" placeholder="Confirm Password" id="txtConfirmPassword" onChange="isPasswordMatch();" >
</div>
<div class="form-group login-input" id="divCheckPassword"></div>
<div class="row">
<div class="col-sm-12">
<button type="submit" name="submit" class="btn btn-default btn-block">Register</button>
</div>
</div>
<?php echo form_close(); ?>
<?php echo $this->session->flashdata('msg'); ?>
</form>
</div>
</div>
</div>
</div>
Here is my error:
Error Number: 1146
Table 'counterpressing.email_id' doesn't exist
SELECT * FROM email_id WHERE email_id = 'shakil#gmail.com' LIMIT 1
Filename: D:/Xampp/htdocs/ffbdhub.com/system/database/DB_driver.php
Line Number: 691
Not sure if this has been brought up, but your validation rule isn't quite right... Your "is_unique()" requires the
table and field, so you have the field name which is email_id, but your table name is nowhere to be seen.
So whatever your table name is for your table containing email_id that you are wanting to check against, you need to change this...
$this->form_validation->set_rules('email_id', 'Email ID', 'trim|required|valid_email|is_unique[email_id]');
To this
$this->form_validation->set_rules('email_id', 'Email ID', 'trim|required|valid_email|is_unique[table_name.email_id]');
In simpler terms, you need to have is_unique[table_name.email_id] , where table_name is the name of the table that contains the email_id you are testing for.
I think you have to load database. Like this
$this->load->database() in file.
This might be solve your problem.

How to retrieve values from database using php and mysql

I am trying to write a script where I need to retrieve email from the database and send a url link to that email,it works, but I want it to be in proper query, since as a beginner I tried but not sure if the queries are correct, I have trouble retrieving the people_id, when the link is sent i am getting the token but not the student_id, how do I fix this issue
<?php
error_reporting(1);
session_start();
include 'includes/db.php';
include 'includes/tokengen.php';
include('classes/phpmailer/phpmailer.php');
if($_POST["Submit"]=="Submit"){
$idcode=$_POST['idcode'];
$_SESSION['idcode'] = $post['idcode'];
$sql = "SELECT * FROM student WHERE idcode = :idcode";
$stmt = $pdo->prepare($sql);
$stmt->bindValue(':idcode', $idcode);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if(!empty($result)){
$email = $result['email'];
//followed a online resource*Doubt
//echo $email;
$token = generateToken();
//echo $token;
$sql = "UPDATE student SET token = :token WHERE email = :email";
//echo $email;
$stmt = $pdo->prepare($sql);
$stmt->execute(array(
':token' => $token,
':email' => $email
));
$result1 = $stmt->fetch(PDO::FETCH_ASSOC);
if(!empty($result)){
$mail = new PHPMailer;
$mail->isSMTP();
//From email address and name
$mail->From = "graymatter.com";
$mail->FromName = "johndoe";
//To address and name
$mail->addAddress("$email", "janedoe");
//echo $email;
//$mail->addAddress("recepient1#example.com"); //Recipient name is optional
//Address to which recipient will reply
$mail->addReplyTo("", "Reply");
//CC and BCC
//$mail->addCC("cc#example.com");
//$mail->addBCC("bcc#example.com");
//Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = "You Registration Link!";
$mail->Body = "http://www.empty.com/register/registration.php?token=$token&student_id=student_id";
$mail->AltBody = 'Click to Register';
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
}
}
else{
echo 'You are not Registered';
}
}
?>
<div class="container">
<div class="row">
<div class="col-md-5 col-md-offset-3 well">
<form role="form" class="form-horizontal" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="regform">
<fieldset>
<legend>Login</legend>
<div class="form-group">
<div class="col-md-3">
<label for="txt_email" class="control-label">CCODE:</label>
</div>
<div class="col-md-9">
<div class="form-inline">
<div class="form-group">
<input class="form-control" type="text" name="idcode" required placeholder="STUDENT ID" value="<?= isset($_SESSION["idcode"]) ? $_SESSION["idcode"] : ""; ?>"/>
<label for="idcode" generated="true" class="error">
<?= isset($error_hash["idcode"]) ? $error_hash["idcode"] : "" ?>
</label>
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input type="submit" name="Submit" value="Submit" class="btn btn-primary"/>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>

else statement no being accessed in php if statement

I am writing a log in script for a site, I have most things working except on a validation mysqli query the else tatement is not being accessed and I cannot figure out how to resolve it, the code below is the index page that has the html and then the php script that is called, All of the php validation works except for the bit of script that validates all the input fields match the database fields, i can get the validation side of the if statement to work and it sends me to the relevent page, the problem is that if the validation in the first part of the if statement shows invalid it doesnt then pass to the else statement, all i get is a blank white page and it is the same as the php page doing the validation not the page i need it to go too. Any help would be most appreciated.
HTML CODE ***********
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Dot Mov Home</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/styles/home.css" rel="stylesheet" type="text/css">
<!--The following script tag downloads a font from the Adobe Edge Web Fonts server for use within the web page. We recommend that you do not modify it.-->
<script>var __adobewebfontsappname__="dreamweaver"</script>
<script src="http://use.edgefonts.net/lemon:n4:default.js" type="text/javascript"></script>
<script src="/js/civem.js"></script>
<script type='text/javascript' src='http://code.jquery.com/jquery.min.js'></script>
<script src="http://code.jquery.com/jquery-1.7.min.js"></script>
<script src="/js/pswrd_strength.js"></script>
<script src="/js/email_dbvalidate.js"></script>
<script src="/js/username_dbvalidate.js"></script>
<script src="/js/confirm_password__dbvalidate.js"></script>
<script type="text/javascript">
function SwapDivsWithClick(div1,div2)
{
d1 = document.getElementById(div1);
d2 = document.getElementById(div2);
if( d2.style.display == "none" )
{
d1.style.display = "none";
d2.style.display = "block";
}
else
{
d1.style.display = "block";
d2.style.display = "none";
}
}
</script>
</head>
<body>
<div id="video_container">
<video muted autoplay loop >
<source src="/video/South Dakota Badlands Scenic Byway 720p (Video Only)_1.3gp" type="video/3gp">
<source src="/video/South Dakota Badlands Scenic Byway 720p (Video Only).webm" type="video/webm">
<source src="/video/South Dakota Badlands Scenic Byway 720p.ogg" type="video/ogg">
Your browser does not support the video tag. I suggest you upgrade your browser. </video>
</div>
<header>
<div class="upload">UPLOAD</div>
<div class="view">VIEW</div>
<div class="spacer1"></div>
<div class="search_bar">
<form action="/search_results.php" method="post" name="search_database" autocomplete="on">
<input type="text" class="search" placeholder="Search">
</form>
</div>
<div class="logo_text">.MOV </div>
<div class="tagline">Motorcycle Online Video</div>
</a></header>
<main>
<div id="login" style="display:block">
<form method="post" action="includes/login.inc.php" id="loginform">
<input name="email" type="email" id="email" form="loginform" placeholder="Please Enter Your Email">
<input name="password" type="password" id="password" form="loginform" placeholder="Please Enter Your Password" title="Please Enter Your Password">
<div class="submit_buttons">
<input type="submit" class="login_btn" form="loginform" formaction="includes/login.inc.php" title="Login" value="Login">
<div class="join_but">Or Join</div>
</div>
<div id="forgotten_password">Forgotten Password</div>
<div class="login_statements">
<div class="statement1">
<div class="by_joining">By Joining</div>
<div class="dot_mov">.MOV</div>
<div class="agree">You agree to our</div>
</div>
<div class="statement2">
<div class="terms_link">Terms of Service</div>
<div class="and">and</div>
<div class="service_link">Privacy Policy</div>
</div>
</div>
<div class="facebook_login">
<div class="facebook_icon"><img src="images/fb.png" class="fb_icon"></div>
<div class="fb_link">Login with FaceBook </div>
</div>
</form>
</div>
</div>
<div id="join" style="display: none;">
<form action="includes/register.inc.php" method="post" id="joinform">
<input name="name2" type="text" id="name2" form="joinform" placeholder="Please Enter Your Username" title="Please Enter Your Username">
<div id="user-name">
<h4>Username must meet the following requirements!<br>If you have forgotten your Password, click on "Forgotten Password"!</h4>
<div id="name_result"></div>
<div id="name_length" class="invalid">At least <strong>6 letters</strong></div>
</div>
<input name="email2" type="email" id="email2" form="joinform" placeholder="Please Enter Your Email" title="Please Enter a Valid Email">
<div id="user-email">
<h4>Email must be a valid Email format!<br>If the Email exists, Either Login using the Username the Email was setup with or check your Email is correct!</h4>
<div id="email_result">
<div id="email_validate" class="invalid">Email Valid</div>
<div id="emaildb_validate"></div>
</div>
</div>
<input name="password2" type="password" id="password2" form="joinform" placeholder="Please Enter Your Password" title="Please Enter Your Password">
<div id="pswd_info">
<h4>Password must meet the following requirements!<br>If the Password doesnt meet the requirements you will be required to fill in the form again!</h4>
<ul id="pswd_list">
<li id="letter" class="invalid">At least <strong>one letter</strong></li>
<li id="capital" class="invalid">At least <strong>one capital letter</strong></li>
<li id="number" class="invalid">At least <strong>one number</strong></li>
<li id="length" class="invalid">Be at least <strong>8 characters</strong></li>
</ul>
</div>
<input name="confirm_password2" type="password" id="confirm_password2" form="joinform" placeholder="Please Confirm Your Password" title="Please Confirm Your Password">
<div id="user-confirm_password">
<h4>Please Confirm Password<br>If the Passwords do not match, you wil be required to fill in the form again!</h4>
<div id="error" class="error"></div>
<div id="confirm_match" class="invalid">Passwords Match</div>
</div>
<div class="submit_buttons2">
<input name="join_btn2" type="submit" id="join_btn2" form="joinform" formaction="includes/register.inc.php" " formmethod="POST" title="Join" value="Join">
<div class="join_btn2">Or Login</div>
</div>
<div class="login_statements2">
<div class="statement1">
<div class="by_joining">By Joining</div>
<div class="dot_mov">.MOV</div>
<div class="agree">You agree to our</div>
</div>
<div class="statement2">
<div class="terms_link">Terms of Service</div>
<div class="and">and</div>
<div class="service_link">Privacy Policy</div>
</div>
</div>
<div class="facebook_login2">
<div class="facebook_icon"><img src="images/fb.png" class="fb_icon"></div>
<div class="fb_link">Login with FaceBook </div>
</div>
</form>
</div>
</div>
</div>
<div class="scroll_container">
<a data-scroll href="#body2"><div class="scroll_link">
<div class="arrow"><img src="/images/arrow.png" alt="" class="arrow_icon"/></div>
<div class="arrow3"><img src="/images/arrow.png" alt="" class="arrow_icon"/></div>
Scroll Down</div></a>
</div>
</main>
<div class="body2" id="body2">
<div class="vid_grid">
<div class="top_section">
<div class="top_left_quarter"></div>
<div class="top_right_quarter">
<div class="top_right_left_quarter"></div>
<div class="top_right_right_quarter"></div>
<div class="top_right_bottom_left"></div>
<div class="top_right_bottom_right"></div>
</div>
</div>
<div class="bottom_section">
<div class="bottpm_left_top"></div>
<div class="bottpm_left_bottom"></div>
<div class="bottom_middle"></div>
<div class="bottom_left_quarter"></div>
<div class="bottom_right_quarter"></div>
<div class="bottom_right_top"></div>
<div class="bottom_right_bottom"></div>
</div>
<div class="staff_picks">Staff Picks </div>
</div>
</div>
<footer class="footer">
<div id="breadcrumbs">Terms &vert; Privacy &vert; About Us &vert; Copyright &vert; Cookies &vert; &reg &copy 2015</div><img src="/images/.mov.png" alt="" width="42" height="14" class="logo"/>
<div class="social_media"><img src="/images/fb.png" alt="" width="30" height="30" class="fbicon"/><img src="/images/twitter.png" alt="" width="32" height="32" class="twittericon"/><img src="/images/googleplus.png" alt="" width="32" height="32" class="googleplusicon"/></div>
</footer>
<script src="/js/smooth-scroll.js"></script>
<script src="/js/smooth-scroll.min.js"></script>
<script type="text/javascript">
smoothScroll.init({
speed: 1000,
easing: 'easeInOutCubic',
offset: 0,
updateURL: true,
callbackBefore: function ( toggle, anchor ) {},
callbackAfter: function ( toggle, anchor ) {}
});
</script>
</body>
</html>
PHP ***************
<?php
include_once 'db_connect.php';
include_once 'functions.php';
sec_session_start();
$emailErr = $passwordErr = $password_matchErr = $email_exsistErr = '';
$email = $name = $password = $confirm_password = '';
if (isset($_POST['name2'], $_POST['email2'], $_POST['paswword2'], $_POST['confirm_password2'])) {
$error_msg .= "please fill in the form";
} else {
// Sanitize the data passed in 'name'
$name = filter_input(INPUT_POST, 'name2', FILTER_SANITIZE_STRING);
// Sanitize the data passed in 'email'
$email = filter_input(INPUT_POST, 'email2', FILTER_SANITIZE_EMAIL);
// validate the data passed in 'email'
$email = filter_var($email, FILTER_VALIDATE_EMAIL);
// check if email is valid
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
// Not a valid email
$emailErr = "The email address you entered is not valid";
}
//Sanitize the data passed in 'password'
$password = filter_input(INPUT_POST, 'password2', FILTER_SANITIZE_STRING);
//validate the data passed in 'password'
if (preg_match("/^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$/", $password)) {
} else {
$passwordErr = "Password is invalid!<br>Please ensure your password is formatted as described when filling in the form!";
}
//Sanitize the data passed in 'confirm_password'
$confirm_password = filter_input(INPUT_POST, 'confirm_password2', FILTER_SANITIZE_STRING);
//check that password and confirm password match
if ($password != $confirm_password) {
// error matching passwords
$confirm_passwordErr = "Your passwords do not match.<br>Please type carefully.";
}
$results = $mysqli->query("SELECT * FROM signed_up WHERE email = `'$email'");`
while($row = $results->fetch_assoc()) {
if ($row["name"] == $name && $row["email"] == $email && $row["password"] == $password) {
$regErr = 'User Already Exsists!<br>Please Login';
$_SESSION['regErr'] = $regErr;
header('location: ../login.php');
} else {
//if ($emailErr == '' && $passwordErr == '' && $password_matchErr == '' && $email_exsistErr =='') {
echo '15';
$_SESSION['emailErr'] = $emailErr;
$_SESSION['passwordErr'] = $passwordErr;
$_SESSION['confirm_passwordErr'] = $confirm_passwordErr;
$_SESSION['email_exsistErr'] = $email_exsistErr;
header('Location: ../join.php');
exit();
}
}
}
//}
?>
This is the section of code where the issue is ***********
$results = $mysqli->query("SELECT * FROM signed_up WHERE email = '$email'");
while($row = $results->fetch_assoc()) {
if ($row["name"] == $name && $row["email"] == $email && $row["password"] == $password) {
$regErr = 'User Already Exsists!<br>Please Login';
$_SESSION['regErr'] = $regErr;
header('location: ../login.php');
} else {
//if ($emailErr == '' && $passwordErr == '' && $password_matchErr == '' && $email_exsistErr =='') {
echo '15';
$_SESSION['emailErr'] = $emailErr;
$_SESSION['passwordErr'] = $passwordErr;
$_SESSION['confirm_passwordErr'] = $confirm_passwordErr;
$_SESSION['email_exsistErr'] = $email_exsistErr;
header('Location: ../join.php');
exit();
}
}
}
//}
?>
edited code that now works ***********************
$results = $mysqli->query("SELECT * FROM signed_up WHERE email = '$email'");
while($row = $results->fetch_assoc()) {
if ($row["name"] == $name && $row["email"] == $email && $row["password"] == $password) {
$regErr = 'User Already Exsists!<br>Please Login';
$_SESSION['regErr'] = $regErr;
header('location: ../login.php');
}else{
$_SESSION['emailErr'] = $emailErr;
$_SESSION['passwordErr'] = $passwordErr;
$_SESSION['confirm_passwordErr'] = $confirm_passwordErr;
$_SESSION['email_exsistErr'] = $email_exsistErr;
header('Location: ../join.php');
exit();
}
}
}
Put your validation directly into SQL
$results = $mysqli->query("SELECT count(*) FROM signed_up WHERE email = '$email' AND name = '$name'");
if ($result->fetchColumn()){
echo "User already exists";
}else{
echo "New user";
}

Categories