Skip to content
Snippets Groups Projects
Commit 7081d297 authored by Suriya Ravichandran's avatar Suriya Ravichandran
Browse files

sign up & login complete

parent c20c8d67
No related branches found
No related tags found
No related merge requests found
......@@ -14,8 +14,8 @@
<div class="wrapper">
<section class="formsignup">
<header> Gochat</header>
<form action="#">
<div class="error-txt"> This the is error msg !</div>
<form action="#" enctype="multipart/form-data">
<div class="error-txt"></div>
<div class="name-details">
<div class="field">
<label>First Name</label>
......@@ -43,7 +43,7 @@
</div>
</div>
</form>
<div class="link">Already signed up? <a href="#">Login now</a></div>
<div class="link">Already signed up? <a href="login.php">Login now</a></div>
</section>
</div>
......
const form = document.querySelector(".formlogin form"),
continueBtn = form.querySelector(".field-gochat-btn input"),
errorText = form.querySelector(".error-txt");
form.onsubmit = (e) => {
e.preventDefault(); // Preventing form from submitting
}
continueBtn.onclick = () => {
// Ajax
let xhr = new XMLHttpRequest(); // Creating XMLHttpRequest object
xhr.open("POST", "php/login.php", true);
xhr.onload = () => {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
let data = xhr.response;
if (data.trim() === "success") {
// Redirect or do something on successful form submission
window.location.href = "users.php";
} else {
// Display error text
errorText.textContent = data;
errorText.style.display = "block";
}
}
}
}
// Handle network errors
xhr.onerror = () => {
console.error("Network error occurred");
};
// We have to send the form data through AJAX to PHP
let formData = new FormData(form); // Creating new FormData object
xhr.send(formData);
}
const form = document.querySelector(".formsignup form"),
continueBtn = form.querySelector(".field-gochat-btn input");
continueBtn = form.querySelector(".field-gochat-btn input"),
errorText = form.querySelector(".error-txt");
form.onsumit = (e)=>{
e.preventDefault(); //preventing form from submitting
form.onsubmit = (e) => {
e.preventDefault(); // Preventing form from submitting
}
continueBtn.onclick = ()=>{
continueBtn.onclick = () => {
// Ajax
let xhr = new XMLHttpRequest(); //creating xml object
let xhr = new XMLHttpRequest(); // Creating XMLHttpRequest object
xhr.open("POST", "php/signup.php", true);
xhr.onload = ()=>{
if(xhr.readyState === XMLHttpRequest.DONE){
if(xhr.status === 200){
xhr.onload = () => {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
let data = xhr.response;
console.log(data);
if (data.trim() === "success") {
// Redirect or do something on successful form submission
window.location.href = "users.php";
} else {
// Display error text
errorText.textContent = data;
errorText.style.display = "block";
}
}
}
}
//we have to send the form data through ajax to php
let formData = new FormData(form); //creating new formData
// Handle network errors
xhr.onerror = () => {
console.error("Network error occurred");
};
// We have to send the form data through AJAX to PHP
let formData = new FormData(form); // Creating new FormData object
xhr.send(formData);
}
\ No newline at end of file
}
......@@ -15,15 +15,15 @@
<section class="formlogin">
<header> Gochat</header>
<form action="#">
<div class="error-txt"> This the is error msg !</div>
<div class="error-txt"></div>
<div class="name-details">
<div class="field">
<label>Email Address</label>
<input type="text" placeholder="Enter your Email">
<input type="text" name="email" placeholder="Enter your Email">
</div>
<div class="field-pass">
<label>Password</label>
<input type="password" placeholder="Enter your password">
<input type="password" name="password" placeholder="Enter your password">
<i class="fas fa-eye"></i>
</div>
<div class="field-gochat-btn">
......@@ -31,10 +31,11 @@
</div>
</div>
</form>
<div class="link">Not yet signed up?<a href="#">signup now</a></div>
<div class="link">Not yet signed up?<a href="index.php">signup now</a></div>
</section>
</div>
<script src="javascript/login.js"></script>
<script src="javascript/login2.js"></script>
</body>
</html>
\ No newline at end of file
php/images/1704501285bank.png

3.15 KiB

<?php
session_start();
include_once "config.php";
$email = mysqli_real_escape_string($conn, $_POST['email']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
if(!empty($email) && !empty($password)){
//let's check users entered email & password matched to database any table row email and password
$sql = mysqli_query($conn, "SELECT * FROM users Where email = '{$email}' AND password = '{$password}'");
if(mysqli_num_rows($sql) > 0){// if users credentials matched
$row = mysqli_fetch_assoc($sql);
$_SESSION['unique_id'] = $row['unique_id'];
echo "success";
}else{
echo "Email or password is incorrect !";
}
}else{
echo "All input fields are required !";
}
?>
\ No newline at end of file
<?php
session_start();
include_once "config.php";
$fname =mysqli_real_escape_string($conn ,$_POST['fname']);
$lname =mysqli_real_escape_string($conn ,$_POST['lname']);
$email =mysqli_real_escape_string($conn ,$_POST['email']);
$password =mysqli_real_escape_string($conn ,$_POST['password']);
$fname = mysqli_real_escape_string($conn, $_POST['fname']);
$lname = mysqli_real_escape_string($conn, $_POST['lname']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
if(!empty($fname) && !empty($lname) && !empty($email) && !empty($password)){
if(filter_var($email, FILTER_VALIDATE_EMAIL)){
// If email is vaild
}else{
if (!empty($fname) && !empty($lname) && !empty($email) && !empty($password)) {
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
// If email is valid
$sql = mysqli_query($conn, "SELECT email FROM users WHERE email = '{$email}'");
if (mysqli_num_rows($sql) > 0) { // If email already exists
echo "$email - This email already exists!";
} else {
$sql = mysqli_query($conn, "SELECT fname FROM users WHERE fname = '{$fname}'");
if (mysqli_num_rows($sql) > 0) { // If username already exists
echo "$fname - Username already exists!";
} else {
// Check if user uploaded a file
if (isset($_FILES['image'])) {
$img_name = $_FILES['image']['name'];
$img_type = $_FILES['image']['type'];
$tmp_name = $_FILES['image']['tmp_name'];
$img_explode = explode('.', $img_name);
$img_ext = end($img_explode);
$extensions = ['png', 'jpeg', 'jpg'];
if (in_array($img_ext, $extensions) === true) {
$time = time();
$new_img_name = $time . $img_name;
if (move_uploaded_file($tmp_name, "images/" . $new_img_name)) {
$status = "Active now";
$random_id = rand(time(), 10000000);
$sql2 = mysqli_query($conn, "INSERT INTO users (unique_id, fname, lname, email, password, img, status)
VALUES ({$random_id},'{$fname}','{$lname}','{$email}','{$password}','{$new_img_name}','{$status}')");
if ($sql2) {
$sql3 = mysqli_query($conn, "SELECT * FROM users WHERE email = '{$email}'");
if (mysqli_num_rows($sql3) > 0) {
$row = mysqli_fetch_assoc($sql3);
$_SESSION['unique_id'] = $row['unique_id'];
echo "success";
}
} else {
echo "something went wrong!";
}
}
} else {
echo "please select an image file - jpeg, jpg, png!";
}
} else {
echo "Please select an Image file!";
}
}
}
} else {
echo "$email - This is not a valid email!";
}
}else{
echo "All input field required!";
} else {
echo "All input fields are required!";
}
?>
\ No newline at end of file
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment