While the same concept is working on other forms for log in function, I'm unable to do so. Help me in login and register. Unable to execute this. Here is code of login and register form and hlater login.php page which should be used for login and register to database. All details are in the code. And kindly report the error and further modification require. Thanks in advance:
<!DOCTYPE html>
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6 lt8"> <![endif]-->
<!--[if IE 7 ]> <html lang="en" class="no-js ie7 lt8"> <![endif]-->
<!--[if IE 8 ]> <html lang="en" class="no-js ie8 lt8"> <![endif]-->
<!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
<head>
<meta charset="UTF-8" />
<!-- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> -->
<title>Login and Registration Form T & P Cell</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Login and Registration Form with HTML5 and CSS3" />
<meta name="keywords" content="html5, css3, form, switch, animation, :target, pseudo-class" />
<meta name="author" content="Codrops" />
<link rel="shortcut icon" href="../favicon.ico">
<link rel="stylesheet" type="text/css" href="css/demo.css" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" type="text/css" href="css/animate-custom.css" />
</head>
<body>
<div class="container">
<!-- Codrops top bar -->
<div class="codrops-top">
<span class="right">
</span>
</div><!--/ Codrops top bar -->
<section style=" height: 480px">
<div id="container_demo" >
<a class="hiddenanchor" id="toregister"></a>
<a class="hiddenanchor" id="tologin"></a>
<div id="wrapper">
<div id="login" class="animate form" style=" height: 270px">
<form action="login.php" method="POST" autocomplete="on">
<h1>Log in</h1>
<p>
<label for="username" class="uname" data-icon="u" > Your email or username </label>
<input id="username" name="username" required="required" type="text" />
</p>
<p>
<label for="password" class="youpasswd" data-icon="p"> Your password </label>
<input id="password" name="password" required="required" type="password" />
</p>
<p class="keeplogin">
<input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping" />
<label for="loginkeeping">Keep me logged in</label>
</p>
<p class="login button" style="float: left">
Not a member? <a href="#toregister" class="to_register" > Join Us </a>
</p>
<p class="login button">
<input type="submit" value="Login" />
</p>
</form>
</div>
<div id="register" class="animate form" style=" height: 400px">
<form action="mysuperscript.php" autocomplete="on">
<h1> Sign up </h1>
<p>
<label for="usernamesignup" class="uname" data-icon="u"> Full name</label>
<input id="usernamesignup" name="usernamesignup" required="required" type="text" />
</p>
<p>
<label for="emailsignup" class="youmail" data-icon="e" > Your email</label>
<input id="emailsignup" name="emailsignup" required="required" type="email" />
</p>
<p>
<label for="passwordsignup" class="youpasswd" data-icon="p">Your password </label>
<input id="passwordsignup" name="passwordsignup" required="required" type="password" />
</p>
<p>
<label for="passwordsignup_confirm" class="youpasswd" data-icon="p">Please confirm your password </label>
<input id="passwordsignup_confirm" name="passwordsignup_confirm" required="required" type="password"/>
</p>
<p class="login button" style="float: left">
Already a member ?
Go and log in
</p>
<p class="signin button">
<input type="submit" value="Sign up"/>
</p>
</form>
</div>
</div>
</div>
</section>
</div>
</body>
</html>
<?php
session_start(); // Starting Session
$error = ''; // Variable To Store Error Message
if (isset($_POST['submit'])) {
echo "string6";
if (empty($_POST['username']) || empty($_POST['password'])) {
echo "gh";
$error = "Username or Password is invalid";
} else {
echo "asdfgh";
// Define $username and $password
$username = $_POST['username'];
$password = $_POST['password'];
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
$connection = mysqli_connect("localhost", "root", "");
// To protect MySQL injection for Security purpose
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysqli_real_escape_string($username);
$password = mysqli_real_escape_string($password);
// Selecting Database
$db = mysqli_select_db("tandp_db", $connection);
// SQL query to fetch information of registerd users and finds user match.
$query = mysqli_query("select * from login where password='$password' AND username='$username'", $connection);
$rows = mysqli_num_rows($query);
if ($rows == 1) {
$_SESSION['login_user'] = $username; // Initializing Session
header("location:login.html"); // Redirecting To Other Page
} else {
$error = "Username or Password is invalid";
}
mysqli_close($connection); // Closing Connection
}
}
?>
in php code below in your script, you are checking this : if (isset($_POST['submit'])), so in the login form give name to submit button :
<input type="submit" name="submit" value="Login" />
Related
I have uploaded all the php files on live server same as on localhost. Few files works fine. But my registration page is not working when i try to register it does not store data in phpmyadmin. and shows the error as below.
enter image description here
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Event Management</title>
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<!--<link href="css/style.css" rel="stylesheet"/>-->
<link href="layout/styles/layout.css" rel="stylesheet" type="text/css" media="all">
<!--<link href="css/bootstrap.css" rel="stylesheet"/>-->
<link href="css/bootstrap.min.css" rel="stylesheet"/>
<script src="js/bootstrap.min.js"></script>
<script src="js/main.js" type="text/javascript"></script>
</head>
<body>
<!-- Database file include -->
<?php require_once ('main.php'); ?>
<!-- Database file include End -->
<div class="container justify-content-center">
<h2 align="center">Log In or Sign Up</h2>
<div class="container">
<form method="post" action="main.php">
<div class="row justify-content-center">
<div class="col-6">
<input type="text" class="form-control" placeholder="Name" name="name"/>
<label></label>
<label></label>
<input type="text" class="form-control" placeholder="username" name="username"/>
<label></label>
<label></label>
<input type="password" class="form-control" placeholder="password" name="password"/>
<label></label>
<label></label>
<input type="email" class="form-control" placeholder="email" name="email"/>
<label></label>
<label></label>
<input type="text" class="form-control" placeholder="contact" name="contact"/>
<label></label>
<label></label><br />
<button class="btn btn-info" id="register" name="register">Register</button>
</div>
</div>
<div class="row justify-content-center">
<div class="col-6">
<label>Already have an Account?</label>
Login Here.
</div>
</div>
</form>
</div>
</div>
</body>
</html>
main.php file code for registration
if(!empty($_POST['name']) && !empty($_POST['username']) && !empty($_POST['password']) && !empty($_POST['email']) && !empty($_POST['contact']))
{
$Name = $_POST['name'];
$uName = $_POST['username'];
$pass = $_POST['password'];
$mail = $_POST['email'];
$contact = $_POST['contact'];
$date = date('d-m-yy');
$mysqli->query("insert into register(Name,username,password,Email_Id,Phone_No,
date_Created) values('$Name','$uName','$pass','$mail','$contact','$date')") or die($mysqli->error);
$mysqli->query("insert into users(email,user_name,pass_word) select r.Email_Id, r.username, r.password from register r where r.Email_Id NOT IN (SELECT email FROM users);") or die($mysqli->error);
echo "Data inserted successfully!";
header('location: login.php');
}
You've an error on main.php line number 73.
Undefined variable: mysqli
Please show more to view & get your solution.
Thanks
I have a login form that requires a username and password. It does tell you when your username and password is wrong but when its correct it just takes you back to login. I have tried everything but the only thing that works is to remove the checklogin.php but then it removes the point of having a login page
Below are my Check Login and Login page scripts:
CHECKLOGIN.PHP
<?php
if(!isset($_SESSION['finance_id']))
echo '<script type="text/javascript">window.location="login.php"; </script>';
?>
LOGIN.PHP
<link rel="shortcut icon" href="img/icon.ico" type="image/x-icon"/>
<?php
include("php/dbconnect.php");
include("php/checklogin.php");
$error = '';
if(isset($_POST['login']))
{
$username = mysqli_real_escape_string($conn,trim($_POST['username']));
$password = mysqli_real_escape_string($conn,$_POST['password']);
if($username=='' || $password=='')
{
$error='All fields are required';
}
$sql = "select * from Finance where username='".$username."' and password = '".md5($password)."'";
$q = $conn->query($sql);
if($q->num_rows==1)
{
$res = $q->fetch_assoc();
$_SESSION['finance_username']=$res['username'];
$_SESSION['finance_id']=$res['id'];
$_SESSION['finance_name']=$res['name'];
echo '<script type="text/javascript">window.location="FinanceManage.php";
</script>';
}else
{
$error = 'Invalid Username or Password';
}
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>iBroker Systems</title>
<!-- BOOTSTRAP STYLES-->
<link href="css/bootstrap.css" rel="stylesheet" />
<!-- FONTAWESOME STYLES-->
<link href="css/font-awesome.css" rel="stylesheet" />
<!-- GOOGLE FONTS-->
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
<style>
.myhead{
margin-top:0px;
margin-bottom:0px;
text-align:center;
}
</style>
</head>
<body >
<div class="container">
<div class="row ">
<div class="col-md-4 col-md-offset-4 col-sm-6 col-sm-offset-3 col-xs-10 col-xs-offset-1">
<div class="panel-body" style="background-color: #FFFFFF; margin-top:50px; border:solid 3px #0e0e0e;">
<h3 class="myhead">iBroker Systems</h3>
<center><img src="img/logo.png"></center>
<form role="form" action="login.php" method="post">
<hr />
<?php
if($error!='')
{
echo '<h5 class="text-danger text-center">'.$error.'</h5>';
}
?>
<h3 class="myhead">Finance Administration</h3>
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-tag" ></i></span>
<input type="text" class="form-control" placeholder="Your Username " name="username" required />
</div>
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-lock" ></i></span>
<input type="password" class="form-control" placeholder="Your Password" name="password" required />
</div>
<center><button class="btn btn-primary" type= "submit" name="login">Login Now</button>
</center>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
Sessions are not initialized in PHP if session_start() is not called, put it in the very beginning of all your scripts
Another thing, for redirection, you better use header('Location: login.php');die();
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
`i have installed a script on my localhost and this error comes up when i try to run the login page. please i need help if there a problem with the code let me know thanks
Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\dating\matchme271\MatchMe2\UPLOAD\index.php on line 180
line 180 is last line
<? php
session_set_cookie_params(172800);
session_start();
require('core/config.php');
require('core/auth.php');
require('core/system.php');
require('core/geo.php');
$auth = new Auth;
$geo = new Geo;
$system = new System;
$system->domain = $domain;
$system->db = $db;
$ip = $_SERVER['REMOTE_ADDR'];
if(isset($_POST['register'])) {
$full_name = ucwords($_POST['full_name']);
$email = $_POST['email'];
$password = trim($_POST['password']);
$time = time();
$age = $_POST['age'];
$gender = $_POST['gender'];
// Geolocation
$longitude = $_SESSION['longitude'];
$latitude = $_SESSION['latitude'];
$geo_info = $geo->getInfo($latitude,$longitude);
$city = $geo_info['geonames'][0]['name'];
$country = $geo_info['geonames'][0]['countryName'];
$check_d = $db->query("SELECT id FROM users WHERE email='".$email."'");
$check_d = $check_d->num_rows;
if($check_d == 0) {
$db->query("INSERT INTO users (profile_picture,full_name,email,password,registered,credits,age,gender,ip,country,city,longitude,latitude) VALUES ('default_avatar.png','$full_name','$email','".$auth->hashPassword($password)."','$time','100','$age','$gender','$ip','".$country."','".$city."','".$longitude."','".$latitude."')");
setcookie('justRegistered', 'true', time()+6);
setcookie('mm-email',$email,time()+60*60*24*30,'/');
header('Location: '.$domain.'/login');
exit;
}
}
if($auth->isLogged()) {
$first_name = $system->getFirstName($_SESSION['full_name']);
}
$users = $db->query("SELECT * FROM users ORDER BY RAND() LIMIT 7");
?>
<!DOCTYPE HTML>
<!--[if lt IE 7 ]><html class="ie ie6 ie-lt10 ie-lt9 ie-lt8 ie-lt7 no-js" lang="en"><![endif]-->
<!--[if IE 7 ]><html class="ie ie7 ie-lt10 ie-lt9 ie-lt8 no-js" lang="en"><![endif]-->
<!--[if IE 8 ]><html class="ie ie8 ie-lt10 ie-lt9 no-js" lang="en"><![endif]-->
<!--[if IE 9 ]><html class="ie ie9 ie-lt10 no-js" lang="en"><![endif]-->
<!--[if gt IE 9]><!-->
<html class="no-js" lang="en"><!--<![endif]-->
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta charset="utf-8">
<title><?php echo $site_name?> - Online Dating Community</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
<link href='//fonts.googleapis.com/css?family=Source+Sans+Pro:400,300,600,700' rel='stylesheet'>
<link href="<?=$system->getDomain()?>/assets/landing/font-awesome-4.3.0/css/font-awesome.min.css" rel="stylesheet">
<link href="<?=$system->getDomain()?>/assets/landing/animate.min.css" rel="stylesheet">
<link rel="stylesheet" href="<?=$system->getDomain()?>/assets/landing/bootstrap-social/bootstrap-social.css">
<link rel="stylesheet" href="<?=$system->getDomain()?>/assets/landing/styles.css">
</head>
<body>
<header class="header header3" role="banner" id="header" style="background-image: url('<?=$system->getDomain()?>/assets/landing/bg-header.jpg')">
<div class="container">
<div style="float:left;position:relative;z-index:2;"> <p><img src="<?=$system->getDomain()?>/img/logo-small.png"></p> </div>
<div class="cnt">
<h4>It’s quick & easy to</h4>
<h1 style="font-size:40px;" class="theme-color">Meet new people online</h1>
<p><?php echo $site_name?> is great for chatting, making friends, sharing interests, and even dating! Did we mention it's free?</p>
</div>
<div class="reg-form has-feedback">
<?php if(!$auth->isLogged()) { ?>
<i class="fa fa-sign-in fa-fw"></i> Log In
<br><br>
<h3>Register in one easy step</h3>
<form action="fb-login.php" method="POST">
<button type="submit" name="fb-login" class="btn btn-subsection btn-social btn-lg btn-facebook" style="text-align:left;"><i class="fa fa-facebook"></i>Log In with Facebook</button> <br>
</form>
<br>
<form action="" method="post" id="registration">
<input type="text" name="full_name" placeholder="Full name" required/>
<input type="text" name="email" placeholder="Email" required/>
<input type="password" name="password" placeholder="Password" required/>
<select name="age" autocomplete="off" required class="form-control">
<option value="" disabled selected>Age</option>
<?php for($i = $minimum_age; $i <= 100; $i++) { ?>
<option value="<?php echo $i?>"> <?php echo $i?> </option>
<?php } ?>
</select>
<select name="gender" autocomplete="off" required class="form-control">
<option value="" disabled selected>Gender</option>
<option value="Male"> Male </option>
<option value="Female"> Female </option>
</select>
<button type="submit" name="register" class="btn-red">Register today!</button>
</form>
<? } else { ?>
<div style="text-align:center;padding-top:50px;">
<h3>Welcome, <b><?=$first_name?></b> </h3>
<form action="<?=$system->getDomain()?>/people" method="GET">
<button type="submit" class="btn-red">Log In</button>
</form>
</div>
<? } ?>
</div>
</div>
</header>
<main class="front-page main" role="main">
<section class="profiles">
<div class="container">
<h3>Meet our community members</h3>
<div class="flexslider carousel">
<ul class="slides">
<?php while($user = $users->fetch_object()) { ?>
<li>
<div class="thumb">
<img src="<?=$system->getProfilePicture($user)?>" style="border-radius:5px;">
</div>
<p><?=$system->getFirstName($user->full_name)?></p>
<span><?=$user->age?>, <?=$user->country?></span>
</li>
<?php } ?>
</ul>
</div>
</div>
</section>
<section class="feature-section">
<h2><?php echo $site_name?> revolutionizes online dating <br/> Give it a try, it’s free to join. </h2>
<div class="container">
<div class="block">
<i class="fa fa-smile-o theme-color"></i>
<h3>It's Free</h3>
<p>
Signing up takes two
minutes and is totally free. What do you have to loose?
</p>
</div>
<div class="block">
<i class="fa fa-check theme-color"></i>
<h3>Smart Matching</h3>
<p>
Our matching algorithm helps
you find the right people.
</p>
</div>
<div class="block">
<i class="fa fa-map-marker theme-color"></i>
<h3>It's Localized</h3>
<p>Connect with the singles from your local <br> town or city.</p>
</div>
</div>
</section>
</main>
<script src="<?=$system->getDomain()?>/assets/landing/scripts/modernizr.js"></script>
<script src="<?=$system->getDomain()?>/assets/landing/scripts/jquery-1.11.0.min.js"></script>
<script src="<?=$system->getDomain()?>/assets/landing/scripts/jquery.flexslider-min.js"></script>
<script src="<?=$system->getDomain()?>/assets/landing/scripts/jquery.parallax-1.1.3.js"></script>
<script src="<?=$system->getDomain()?>/assets/landing/scripts/jquery.localscroll-1.2.7-min.js"></script>
<script src="<?=$system->getDomain()?>/assets/landing/scripts/jquery.scrollTo-1.4.2-min.js"></script>
<script src="<?=$system->getDomain()?>/assets/landing/scripts/jquery.inview.min.js"></script>
<script src="<?=$system->getDomain()?>/assets/landing/scripts/theme.js"></script>
<script>
navigator.geolocation.getCurrentPosition(getPosition);
function getPosition(position) {
$.get('<?=$system->getDomain()?>/ajax/setPosition.php?longitude='+position.coords.longitude+'&latitude='+position.coords.latitude);
}
</script>
</body>
</html>
The problem is lines like these:
<? } else { ?>
<? } ?>
The first <? should be <?php
I cannot seem to link my login page to my home page, any help would be much appreciated. I know its connecting to the database as i can create users but for some reason its not letting me sign in with a created user.
<?php require ("insert.php"); ?>
<?php
if(isset($_POST[ 'Login' ]))
{
$email= mysqli_real_escape_string($con, $_POST ['email']);
$pswrd= mysqli_real_escape_string($con, $_POST ['pswrd']);
$result = $con->query (" select * from users where email='$email' AND pswrd='$pswrd' ");
$row = $result->fetch_array(MYSQLI_BOTH);
session_start();
$_SESSION["User ID"] = $row['UserID'];
header ('Location: home.php');
}
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>AMSadler login</title>
<meta charset="utf-8">
<meta name="description" content="description of webpage">
<meta name="keywords" content="keywords go here">
<meta name="author" content="Anthony">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/login.css">
<link rel="index" href="index.php">
<link rel="icon" href="img/favicon.png" sizes="16x16" type="image/png">
</head>
<body>
<div class="header">
<div id="logo">
<img src="img/logo.png" alt="logo" title="AMSadler.com"/>
</div>
<div id="signup">
<button type="button">Sign up</button>
</div>
</div>
<div id="login">
<form>
<input type="text" name="email" placeholder="Email address">
<br>
<input type="password" name="password" placeholder="Password">
<br>
<input id="Login" type="submit" name="Login" value="Login">
</form>
</div>
<footer>
<div id="copyright">
<p>© Copyright 2015</p>
</div>
</footer>
</body>
</html>
You need to change your form tags.
From,
<form>
To,
<form action="yourPageName.php" method="post">
You need to specify your method type so in your PHP code you can get it using that method. If you leave out the method part it by default uses $_GET. Seeing as your code is pointing to $_POST then you set it to method="post".
You also need to set action="" this can be set to # for same page or leave it blank or using a file name. This will redirect the form to that page.
I am trying to echo a whole html code. I am using foundation 5 and if I try to make a form variable inside the php code block, there is an error stating that the classes used in foundation 5 are not functionable. As you can see this is not a finished code so I am just looking for answers right now.
Here is my code:
<?php
session_start();
?>
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>AskmanProducts</title>
<link rel="stylesheet" href="css/foundation.css" />
<script src="js/vendor/modernizr.js"></script>
<script src="js/signinvaldator.js"></script>
</head>
<body>
<div class="row" style="margin-top:10%">
<div align="center"><h2>Log In To Access This Website</h2></div>
<br />
<div class="medium-6 medium-centered large-centered large-6 columns">
<form data-abide>
<div class="name-field">
<label for="username">Username</label>
<input id="username" type="text" required="" name="user"></input>
<small class="error" data-error-message="">A username is required.</small>
</div>
<label for="password">Password</label>
<input id="password" type="password" required="" name="password"></input>
<small class="error">A Password is required.</small>
<br />
<br />
<button type="submit" name="loginbtn">Log In</button>
Sign Up
Forgot Password?
<br />
</form>
</div>
</div>
<?php
if ($_POST['loginbtn']) {
$user = $_POST['user'];
$password = $_POST['password'];
}
else
echo
?>
<script src="js/vendor/jquery.js"></script>
<script src="js/foundation.min.js"></script>
<script>
$(document).foundation();
</script>
</body>
</html>
Rename your html file as php. Example: index.html -> index.php