Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My data is printing fine on the page but the data which we are inserting is not saved in the database


What I have tried:

<?php
 include "config.php";
if(isset($_POST['submit']))
{
	$name=$_POST['name'];
	$username=$_POST['username'];
	$password=$_POST['password'];
	$confirmpassword=$_POST['confirmpassword'];
	$email=$_POST['email'];
	$sql="INSERT INTO register( name, username, password, confirmpassword, email) VALUES ('$name','$username','$password','$confirmpassword','$email')";
	if(mysqli_query($conn,$sql))
	{
		?>
		<script type="text/javascript">
			alert("data is saved succesfully");
		</script>
		<?php
	}
	else{
	?>
		<script type="text/javascript">
			alert("data is not saved succesfully");
		</script>
		<?php	
	}
}
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
</head>
<body>
<form action="signup.php" method="POST">
	<h1>Registration Page</h1>
	Name:<input type="text" name="name" placeholder="Enter your name" required><br>
	Username:<input type="text" name="username" placeholder="Enter your username" required><br>
	Password:<input type="password" name="password" placeholder="Enter your password" required><br>
	ConfirmPassword:<input type="password" name="confirmpassword" placeholder="Enter your confirmpassword" required><br>
	Email:<input type="text" name="email" placeholder="Enter your Email" required><br>
   <input type="submit" name="submit" value="Register">
  <p>
  		Already a member? <a href="login.php">Sign in</a>
  	</p>
</form>
</body>
</html>
Posted
Comments
Luc Pattyn 28-Mar-22 15:43pm    
Your problem description is not OK:
- "prints fine", what does that mean?
- If you get one of the alerts, then tell us which.
- "not saved to database" is based on what?

And how about $conn? It appears only once in the code shown...

BTW: on top of it not working, you will get comments about:
- storing passwords as text,
- storing a confirmpassword rather than comparing it right away,
- being a candidate for SQL injection attacks.

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