Reputation: 9
I am trying to get this PHP code working with my html. The PHP alone work but when im trying to use the html form and use PHP code it does not do anything at all. I've been trying to figure this out but without any success. Can somebody please explain what I am doing wrong?
<?php
include_once("config.php");
if(isset($_POST['submit'])){
//Perform the verification
$uname = $_POST['uname'];
$email = $_POST['email'];
$email2 = $_POST['email2'];
$pass = $_POST['pass'];
$pass2 = $_POST['pass2'];
if($email == $email2){
if($pass == $pass2){
//All good. Carry on.
$query = $sql->prepare("INSERT INTO login (uname, email, pass) VALUES (?, ?, ?)");
$query->bind_param('sss', $uname, $email, $pass );
$query -> execute();
header("Location: index.html");
}else{
echo "Passwords do not match.<br />";
exit();
}
}else{
echo "Emails do not match.<br /><br />";
exit();
}
$sql->close();
$query->close();
}
?>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div class="container">
<section>
<div id="container_demo" >
<a class="hiddenanchor" id="tologin"></a>
<div id="wrapper">
<div id="login" class="animate form">
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<h1> Sign up </h1>
<p>
<label for="usernamesignup" class="uname" data-icon="u">Username</label>
<input id="usernamesignup" name="usernamesignup" required="required" type="text"/>
</p>
<p>
<label for="emailsignup" class="email" data-icon="e"> Your email</label>
<input id="emailsignup" name="emailsignup" required="required" type="email"/>
</p>
<p>
<label for="emailsignup" class="email2" data-icon="e">Confirm your email</label>
<input id="emailsignup" name="emailsignup" required="required" type="email"/>
</p>
<p>
<label for="passwordsignup" class="pass" data-icon="p">Your password </label>
<input id="passwordsignup" name="passwordsignup" required="required" type="password"/>
</p>
<p>
<label for="passwordsignup_confirm" class="pass2" data-icon="p">Please confirm your password </label>
<input id="passwordsignup_confirm" name="passwordsignup_confirm" required="required" type="password"/>
</p>
<p class="signin button">
<input type="submit" value="Sign up"/>
</p>
<p class="change_link">
Already a member ?
<a href="index.html" class="to_register"> Go and log in </a>
</p>
</form>
</div>
</div>
</div>
</section>
</div>
</body>
</html>
Upvotes: 0
Views: 261
Reputation: 612
EXTRA TIP : Your HTML textbox name is mismatch with the $_POST variable, I'll give a short example : <input type="text" name="usernamesignup" />
should be $_POST["usernamesignup"], not $_POST["uname"].
Upvotes: 0
Reputation: 16107
You did not give your submit button a name.
<input type="submit" value="Sign up"/>
Without a name, the value of the input
won't be sent to the server. Basically submitting the form will find that if(isset(
and skip the entire code.
Upvotes: 0
Reputation: 827
You should add the name="submit"
attribute to your submit button. Otherwise $_POST['submit']
will never be set, and nothing will happen.
Upvotes: 0
Reputation: 64526
Your problem is here, you're checking if there is a post variable named submit
:
if(isset($_POST['submit'])){
But your form doesn't have any input named submit
. I suggest changing to:
if($_SERVER['REQUEST_METHOD'] == 'POST'){
Checking the REQUEST_METHOD
is better because it doesn't rely on the submit button being present in the post data.
Upvotes: 2