TomCreed TomCreed - 10 months ago 65
MySQL Question

PHP POST method not working?

I am a complete beginner and am trying to make a form for a project at university. I am just learning php and I am trying to test whether or not I can take the values from my php form and output it before I move on to linking it to my database. This is my full code for my login page, which btw I used bootstrap for some of the frame work. So I have tried to use the POST method and echo out first name and last name to see if it works, and it just wont echo out when I press the submit button. This is really frustrating me. Don't worry about the style, I just want to get the functionality out of the way first, and yes the page is called index.php .



<!doctype html>
<html lang='en'>
<head>
<title>Create Employee Account</title>

<!-- Required meta tags -->
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1, shrink-to-fit=no'>

<!-- Bootstrap CSS -->
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css' >


<link rel='stylesheet' href='no_dashboard_css_template.css'>
<link rel='stylesheet' href= ''>
</head>

<body>

<?php
include 'dbconnect.php';

if(isset($POST['submit']))
{
$firstName=$_POST['firstname'];
$lastName=$_POST['lastname'];
$email=$_POST['email'];
$password1=$_POST['password1'];
$password2=$_POST['password2'];
}
echo $firstName;
echo $lastName;

?>


<!-- NAVIGATION BAR -->

<nav class='navbar navbar-expand-lg navbar-light bg-light'>
<img id='logo' src='logo.png'>
<button class='navbar-toggler' type='button' data-toggle='collapse' data-target='#navbarSupportedContent' aria-controls='navbarSupportedContent' aria-expanded='false' aria-label='Toggle navigation'>
<span class='navbar-toggler-icon'></span>
</button>

<div class='collapse navbar-collapse' id='navbarSupportedContent'>
<ul class='navbar-nav mr-auto'>
<li class='nav-item active'>
<a class='nav-link' href='#'>Home/Login<span class='sr-only'>(current)</span></a>
</li>
</ul>
</div>
</nav>
<!-- Main CONTAINER part of the page WHERE MOST PAGE CONTENT WILL GO -->
<div class='container-fluid'>

<div class='row'>

<!-- EMPLOYEE SIGN UP AREA -->

<div class='col-lg-4'>
<h3>Potential Employee Sign Up</h3>

<!-- EMPLOYEE SIGN UP FORM -->
<form action='index.php' method='POST' >

<!-- Title (Mr Mrs etc. -->
<label class='mr-sm-2' for='inlineFormCustomSelectPref'>Title</label>
<select name='title' class='custom-select mb-2 mr-sm-2 mb-sm-0' id='inlineFormCustomSelectPref'>
<option selected>Choose...</option>
<option value='1'>Mr</option>
<option value='2'>Ms</option>
<option value='3'>Mrs</option>
</select>
<br>

<!-- NAMES -->
<div class='row'>

<!-- First Name -->
<div class='col'>
<input type='text' class='form-control' name='firstname' placeholder='First name'>
</div>

<!-- Last Name -->
<div class='col'>
<input type='text' class='form-control' name='lastname' placeholder='Last name'>
</div>
</div>

<!-- Email and Password-->
<div class='form-group'>
<label for='exampleInputEmail1'>Email address</label>
<input type='text' class='form-control' id='exampleInputEmail1' name='email' placeholder='Enter email'>
</div>
<div class='form-group'>
<label for='exampleInputPassword1'>Password:</label>
<input type='password' class='form-control' name='password1' id='exampleInputPassword1' placeholder='Password'>
<label for='exampleInputPassword1'>Enter your Password again:</label>
<input type='password' class='form-control' name='password2' id='exampleInputPassword1' placeholder='Password'>
</div>
<!-- Terms and Conditions-->
<div class='form-check'>
<label class='form-check-label'>
<input type='checkbox' class='form-check-input'>
I have agreed and read the Terms and conditions
</label>
</div>

<!-- Education -->
<!-- University -->
<div class='form-group'>
<label for='exampleFormControlInput1'>University</label>
<input type='text' class='form-control' name='uni' id='exampleFormControlInput1' placeholder='Please Type your University'>
</div>
<!-- Degree Type -->
<label class='mr-sm-2' for='inlineFormCustomSelectPref'>Degree Type</label>
<select class='custom-select mb-2 mr-sm-2 mb-sm-0' name='degtype' id='inlineFormCustomSelectPref'>
<option selected>Choose...</option>
<option value='1'>BEng</option>
<option value='2'>MEng</option>
<option value='3'>MSc</option>
</select>
<br>
<!-- End Button to submit -->
<button type='submit' class='btn btn-primary' name='submit' >Sign Up!</button>


</form>

</div>
</div>
</div>

<!-- EMPLOYEE SIGN UP AREA END -->

<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src='https://code.jquery.com/jquery-3.2.1.slim.min.js' ></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js' ></script>
<script src='https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js' ></script>
</body>
</html>




Answer Source

Your mistake is on this line

if(isset($POST['submit']))

Use it

if(isset($Ů€POST['submit']))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download