<?php
function log_page(){
print_r($_POST);
//connection variables
$host = 'localhost';
$user = 'root';
$password = '';
$db = 'firstwebsite';
//create mysql connection
$mysqli = mysqli_connect($host,$user,$password);
if(!$mysqli){
echo " connection";
}
else{
echo "no connection";
}
$select = mysqli_select_db( $mysqli, $db);
$_SESSION['message']='';
if (isset($_POST['register'])) {
if ($_POST['password'] == $_POST['confirmpassword'])
{
$$username = $mysqli->real_escape_string($_POST['username']);
$email = $mysqli->real_escape_string($_POST['email']);
$password = md5($_POST['password']);
echo $username . " " . $email . " " . $password;
}
}
?>
<link rel="stylesheet" href="log_style.css" type="text/css">
<div class="body-content">
<div class="module">
<h1>Create an account</h1>
<form class="form" action="log_page.php" method="post" autocomplete="off">
<input type="text" placeholder="User Name" name="username" required />
<input type="email" placeholder="Email" name="email" required />
<input type="password" placeholder="Password" name="password" autocomplete="new-password" required />
<input type="password" placeholder="Confirm Password" name="confirmpassword" autocomplete="new-password" required />
<input type="submit" value="Register" name="register" class="btn btn-block btn-primary" />
<input type="submit" value="Already registered? Sign in" name="register2" class="btn btn-block btn-primary" />
</form>
</div>
</div>
<?php
}
?>
my code is not printing anything when i ask for echoing username and email and password. it is not entering the $_POST['register'] if statement. I think the php code is executed before the form values getting executed