Click here to Skip to main content
15,035,600 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
 here is my register.php
<?php
require_once('dbconnect.php');
session_start();

$name=$email=$password="";

if(isset($_POST['Sign Up'])){

$name = trim($_POST['name']);
$email = trim($_POST['email']);
$password = trim($_POST['password']);

$sql = "INSERT INTO users1 values('$name','$email','$password')";

$query = mysqli_query($conn,$sql);

if($query){
    echo "<script>alert('Your are registered successfully!!')</script>";
}
else{
echo "<script>alert('Sorry!! Error!!')<script>";
}
}
else{

}
$email=$password="";
if(isset($_POST['Sign In'])){

$email=trim($_POST['email']);
$password=trim($_POST['password']);
if(!$email==''&& !$password==''){
	
$sql = "SELECT * FROM users1 where email='$email' and password='$password'";

$query = mysqli_query($conn,$sql);

$count = mysqli_num_rows($query);

if($count == 1){
	$_SESSION['email']=$email;
	 header("location:login.php");
}
else{
    echo "<script>alert('Email and Password is incoreect!!')</script>";
   }
 }
else{
echo "<script>alert('All fields should not be blank!!')<script>";
}
}
else{

}

?>

<!--<%@page contentType="text/html" pageEncoding="UTF-8"%> -->
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Animal Adoption System</title>
        
        <style>
            
@import url('https://fonts.googleapis.com/css?family=Montserrat:400,800');

* {
    box-sizing: border-box;
}

.nav-area {
	float: right;
	list-style: none;
	margin-top: 30px;
}
.nav-area li {
	display: inline-block;
}
.nav-area li a {
	color: #000;
	text-decoration: none;
	padding: 5px 20px;
	font-family: poppins;
	font-size: 16px;
	text-transform: uppercase;
}
.nav-area li a:hover {
	background: #fff;
	color: #333;
}

.logo {
	float: left;
}
.logo img {
	width: 100%;
	padding: 15px 0;
}


body {
	background: #FF416C;
	display: flex;
	justify-content: center;
	align-items: center;
	flex-direction: column;
	font-family: 'Montserrat', sans-serif;
	height: 100vh;
	margin: -20px 0 50px;
}

.center{
	margin-bottom: 10px;
} 

h1 {
	font-weight: bold;
	margin: 0;
}

h2 {
	text-align: center;
}

p {
	font-size: 14px;
	font-weight: 100;
	line-height: 20px;
	letter-spacing: 0.5px;
	margin: 20px 0 30px;
}

span {
	font-size: 12px;
	margin-bottom: 15px;
}

a {
	color: #333;
	font-size: 14px;
	text-decoration: none;
	margin: 15px 0;
}

button {
	border-radius: 20px;
	border: 1px solid #FF4B2B;
	background-color: #FF4B2B;
	color: #FFFFFF;
	font-size: 12px;
	font-weight: bold;
	padding: 12px 45px;
	letter-spacing: 1px;
	text-transform: uppercase;
	transition: transform 80ms ease-in;
}

button:active {
	transform: scale(0.95);
}

button:focus {
	outline: none;
}

button.ghost {
	background-color: transparent;
	border-color: #FFFFFF;
}

form {
	background-color: #FFFFFF;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-direction: column;
	padding: 0 50px;
	height: 100%;
	text-align: center;
}

input {
	background-color: #eee;
	border: none;
	padding: 12px 15px;
	margin: 8px 0;
	width: 100%;
}

.container {
	background-color: #fff;
	border-radius: 10px;
  	box-shadow: 0 14px 28px rgba(0,0,0,0.25), 
			0 10px 10px rgba(0,0,0,0.22);
	position: relative;
	overflow: hidden;
	/* width: 768px; */
	max-width: 100%;
	/* min-height: 480px; */
	width:750px;
	height: 400px;
}

.form-container {
	position: absolute;
	top: 0;
	height: 100%;
	transition: all 0.6s ease-in-out;
}

.sign-in-container {
	left: 0;
	width: 50%;
	z-index: 2;
}

.container.right-panel-active .sign-in-container {
	transform: translateX(100%);
}

.sign-up-container {
	left: 0;
	width: 50%;
	opacity: 0;
	z-index: 1;
}

.container.right-panel-active .sign-up-container {
	transform: translateX(100%);
	opacity: 1;
	z-index: 5;
	animation: show 0.6s;
}

@keyframes show {
	0%, 49.99% {
		opacity: 0;
		z-index: 1;
	}
	
	50%, 100% {
		opacity: 1;
		z-index: 5;
	}
}

.overlay-container {
	position: absolute;
	top: 0;
	left: 50%;
	width: 50%;
	height: 100%;
	overflow: hidden;
	transition: transform 0.6s ease-in-out;
	z-index: 100;
}

.container.right-panel-active .overlay-container{
	transform: translateX(-100%);
}

.overlay {
	background: #FF416C;
	background: -webkit-linear-gradient(to right, #00fecb, #FF416C);
	background: linear-gradient(to right, #FF416C, #00fecb );
	background-repeat: no-repeat;
	background-size: cover;
	background-position: 0 0;
	color: #FFFFFF;
	position: relative;
	left: -100%;
	height: 100%;
	width: 200%;
  	transform: translateX(0);
	transition: transform 0.6s ease-in-out;
}

.container.right-panel-active .overlay {
  	transform: translateX(50%);
}

.overlay-panel {
	position: absolute;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-direction: column;
	padding: 0 40px;
	text-align: center;
	top: 0;
	height: 100%;
	width: 50%;
	transform: translateX(0);
	transition: transform 0.6s ease-in-out;
}

.overlay-left {
	transform: translateX(-20%);
}

.container.right-panel-active .overlay-left {
	transform: translateX(0);
}

.overlay-right {
	right: 0;
	transform: translateX(0);
}

.container.right-panel-active .overlay-right {
	transform: translateX(20%);
}

.social-container {
	margin: 20px 0;
}

.social-container a {
	border: 1px solid #DDDDDD;
	border-radius: 50%;
	display: inline-flex;
	justify-content: center;
	align-items: center;
	margin: 0 5px;
	height: 40px;
	width: 40px;
}


        </style>
        
    </head>
    <body>

<header>
        <div class="logo">
            <img src="https://i.postimg.cc/mg4rWBmv/logo.png" alt="">
        </div>
<ul class="nav-area">
<li><a href="Home.html">Home</a></li>
<li><a href="About.html">About</a></li>
<li><a href="Services.html">Services</a></li>
<li><a href="Adoption form.html">Adoption form</a></li>
<li><a href="Contact.html">Contact</a></li>
<li><a href="register.php">register</a></li>
<li><a href="register.php">signin</a></li>
</ul>
</div>
</header>
        
        <div class="container" id="container">
            <div class="form-container sign-up-container">
                <form action="register.php" method="post">
                    <h1>Create Account</h1>
			        <span>or use your email for registration</span> 
			        <input type="text" name="name" placeholder="Name" required/>
			        <input type="email" name="email" placeholder="Email" required/>
			        <input type="password" name="password" placeholder="Password" required/>
			        <button type="submit">Sign Up</button>
		        </form>
	        </div>
	        <div class="form-container sign-in-container">
		        <form action="login.html" method="post">
			        <h1>Sign in</h1>
			        <span>or use your account</span> 
			        <input type="email" name="email" placeholder="Email" required/>
			        <input type="password" name="password" placeholder="Password" required/>
			        <a href="#">Forgot your password?</a>
			        <button type="submit">Sign In</button>
		        </form>
	        </div>
	        <div class="overlay-container">
		        <div class="overlay">
			        <div class="overlay-panel overlay-left">
						<img src = "https://i.postimg.cc/mg4rWBmv/logo.png" width="80" height="80" class = "center">
				        <h1>Welcome Back!</h1>
				        <p>To participate, please connect through your college info!</p>
				        <button class="ghost" id="signIn">Sign In</button>
			        </div>
			        <div class="overlay-panel overlay-right">
						<img src = "https://i.postimg.cc/mg4rWBmv/logo.png" width="80" height="80" class = "center">
				        <h1>Hello All!</h1>
				        <p>Enter your details and start your journey with us</p>
				        <button class="ghost" id="signUp" >Sign Up</button>
			        </div>
		        </div>
	        </div>
        </div>
    </body>
    
    <script>
            const signUpButton = document.getElementById('signUp');
            const signInButton = document.getElementById('signIn');
            const container = document.getElementById('container');

            signUpButton.addEventListener('click', () => {
            container.classList.add("right-panel-active");
            });

            signInButton.addEventListener('click', () => {
            container.classList.remove("right-panel-active");
            });
        </script>
</html>


<pre lang="text">here is my dbconnect.php


<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD','');
define('DB_NAME','assign1');

$conn = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_NAME);

if($conn===false){
    die("Error:Could not Connect ".mysqli_connect_error());
}
?>


What I have tried:

I have tried everything on the internet but nothing worked.
Posted
Updated 1-Jun-21 16:28pm
Comments
Richard Deeming 2-Jun-21 8:45am
   
In addition to the SQL Injection[^] vulnerability, you are storing passwords in plain text. NEVER do that!

Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]

PHP even has built-in functions to help you do the right thing:
PHP: password_hash[^]
PHP: password_verify[^]

If you carry on with this code, I hope you've got very deep pockets - you face being fined millions of dollars by multiple regulators when your database is breached.

Quote:
My code is not inserting data into my database

One possible reason is SQL Injection.
PHP
$sql = "INSERT INTO users1 values('$name','$email','$password')";

Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]
   
As Patrice T pointed out one very potential reason is that your SQL statement has a parse error because of illegal characters. This can and should be avoided by using bind variables.

In order to get more information about the error at hand you can use mysqli_error to fetch the error message. In other words, your code could look something like
PHP
...
if($query){
    echo "<script>alert('Your are registered successfully!!')</script>";
}
else{
echo "<script>alert('Sorry!! Error!!'):" . mysqli_error($conn) . "<script>";
}
...

For more information, see PHP mysqli error() Function[^]
   
Comments
Shweta Gaikwad 2021 2-Jun-21 7:19am
   
I tried but It didn't work
Wendelius 2-Jun-21 8:24am
   
In order to solve the problem, details are needed.
What was the error message you got?
Shweta Gaikwad 2021 2-Jun-21 8:38am
   
I didn't get any error messages. It directly takes me to the webpage and when I enter information it not showing in my database.
Wendelius 2-Jun-21 9:00am
   
The key here is to debug your code to get more information out of the situation. For example, have a look at A Detailed Guide to PHP Debugging – Stackify[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900