I am trying to write a simple code for php form. I wrote the php code in the same page as html. Name of the php page is signup.php But I am getting error like this:
Notice: Undefined index: nm in C:\xampp\htdocs\mini_project\signup2.php on line 5
Notice: Undefined index: email in C:\xampp\htdocs\mini_project\signup2.php on line 6
If I separate the php and html code in two different pages there is no problem with my code.
Why can't I write php and html in the same page? What I am doing wrong?
I am using php 7.
<?php
include 'connect.php'
$nm = $_POST['nm'];
$email = $_POST['email'];
$password = $_POST['password'];
$cpassword = $_POST['cpassword'];
$type = $_POST['type'];
$remember = $_POST['remember'];
$signup = $_POST['signup'];
if (isset($signup))
{
$query = "INSERT INTO user_details (nm,email,pass,user_type) VALUES ('$nm','$email','$password','$type')";
$result = mysqli_query($conn,$query);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<body>
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="login-panel panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Please Sign In</h3>
</div>
<div class="panel-body">
<form role="form" method="post" action="signup.php">
<fieldset>
<div class="form-group">
<input class="form-control" placeholder="Please Enter Name" name="nm" id="nm" type="text" autofocus>
</div>
<div class="form-group">
<input class="form-control" placeholder="Please Enter E-mail" name="email" id="email" type="email">
</div >
<div class="form-group">
<input class="form-control" placeholder="Please Enter Password" name="password" id="password" type="password" value="">
</div>
<div class="form-group">
<input class="form-control" placeholder="Please Confirm Password" name="cpassword" id="cpassword" type="password" value="">
</div>
<div class="form-group">
<select class="form-control" align="center" name="type">
<option value="0">Please Select User Type</option>
<option value="1">I want to Hire</option>
<option value="Second Year">I want to Work</option>
</select>
</div>
<div class="checkbox">
<label>
<input name="remember" id="remember" type="checkbox" value="Remember Me">Remember Me
</label>
</div>
<!-- Change this to a button or input when using this as a form -->
<input type="submit" name="signup" id="signup" value="Signup" class="btn btn-lg btn-primary btn-block">
</fieldset>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>