i am new to php. I am trying to do login and registration in php mysql. for that i create one simple form and tested whethet the data was inserted in phpmyadmin or not. The values are not saving in db. I dont know where is the error.
I have include the coding below
MY Db connection:
<?php
$connect = mysql_connect("localhost", "root", "") or die("Unable to connect database".mysql_error());
mysql_select_db("logindb", $connect) or die ("sorry db connection fail");
?>
My Registratiion form:
<?php
include("config.php");
?>
<!DOCTYPE html>
<html>
<head>
<title>Login screen</title>
<style type="text/css">
.register-form{
width: 500px;
margin: 0 auto;
text-align: center;
padding: 10px;
padding: 10px;
background : #c4c4c4;
border-radius: 10px;
-webkit-border-radius:10px;
-moz-border-radius:10px;
}
.register-form form input{padding: 5px;}
.register-form .btn{
background: #726E6E;
padding: 7px;
border-radius: 5px;
text-decoration: none;
width: 50px;
display: inline-block;
color: #FFF;
}
.register-form .register{
border: 0;
width: 60px;
padding: 8px;
}
</style>
</head>
<body>
<?php
if(isset($_POST['submit']))
{
$name=mysql_real_escape_string($_POST['username']);
$email=mysql_real_escape_string($_POST['email']);
$password=mysql_real_escape_string($_POST['password']);
$cpassword=mysql_real_escape_string($_POST['confirmpassword']);
$query = mysql_query("inser into register values('', '$name', '$email', '$password', '$cpassword')");
if($query)
{
header("location:success.php");
}
}
?>
<div class="register-form">
<h1>Register</h1>
<form action="" method="post">
<p><label>User Name: </label>
<input type="text" id="username" name="username" placeholder="Username">
</p>
<p><label>E-Mail :</label>
<input id="email" name="email" type="email">
</p>
<p><label>Password :</label>
<input id="password" name="password" type="password">
</p>
<p><label>confirm Password :</label>
<input id="confirmpassword" name="confirmpassword" type="password">
</p>
<input type="submit" name="submit" value="register" class="btn register">
<a class="btn" href="login.php">Login</a>
</form>
</div>
</body>
</html>
After success in create a new page i redirect to success.php
<!DOCTYPE html>
<html>
<head>
<title>success full</title>
</head>
<body>
<h1>Successfully registered</h1>
</body>
</html>
After i enter data, i click submit. i was echo and saw the sql queries, i am getting value but its not saving in phpmyadmin database. I am new to php, please help me to develop more php.
Once again i am thank you.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…