php checkout login

So I have a checkout page with a login on the bottom right now. I want to have the code be something like if the user enters a correct login a different for pops up in place of the login form, if not the login form stays and says “credentials were wrong”. How can i do this I tried below but it doesnt seem to work. The login works fine for my purposes but gettin the forms to work is giving me a headache. Any ideas?

[php]<?php
if(isset($_POST[“submit”])){
try
{
$pdo = new PDO(‘mysql:host=localhost;dbname=DV8’,‘root’,‘root’);
}
catch(PDOException $e){
die($e->getmessage());
}
$sql = “select id from users where username=:username and password = :password”;
$stmt = $pdo->prepare($sql);

        $stmt->bindParam(":username", $_POST['username']);
        $stmt->bindParam(":password", $_POST['password']);
        $stmt->execute();
        if($result=$stmt->fetch(PDO::FETCH_OBJ)){
           echo "successful";
           displayUserInfo();
    }else{
        echo "credentials were wrong";
        displayForm();
    }
}else{
    displayForm();
}

?>

<html>
<body> 
        <?php
         function displayForm(){
            ?>
	<form action="" method="POST">
		<p>Username:</p><input type="text" name="username" />
		<p>Password:</p><input type="password" name="password" />
		<br />
		<input type="submit" value="Login" name="submit" id="submitted"/>
	</form>
	<?php
        }?>
	
            
            <?php function displayUserInfo(){
                ?>
            <form action="" method="post">
                <input type="text"/>
                 <input type="text"/>
                  <input type="text"/>
                   <input type="text"/>
            </form>
            <?php
            
            }?>

</body>
[/php]

Could you not just check to see if the user is logged in display one form, if not logged in keep displaying the login form.

[php]if(logged-in){
function displayUserInfo();
echo’




';
}else{
function displayForm();
echo ’

Username:


Password:





';
}[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service