Hi there,
I am trying to use a login and a contact form on one page, but im struggling with the php context

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<head>
  <title>my webpage</title>
</head>

<body>
<?php
$user = 'admin';
$pass = 'admin';

if ($user != $_POST['username'] || $pass != $_POST['password']) { ?>

<form method="post" >
Enter username:
<input type="text" name="username" /><br/>
Enter Password:
<input type="password" name="password" /><br/>
<center><input type="submit value="login" /></center>

<?php } else { ?>

 <?php 
if ($_POST["email"]<>'') { 
	$ToEmail = 'my email
	$EmailSubject = 'subject
	$mailheader = "From: ".$_POST["email"]."\r\n"; 
	$mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
	$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
	$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>"; 
	$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>";
	$MESSAGE_BODY .= "comment".$_POST["comment"]."<br>";

mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");

<p>Thank you for your comment</p>

<?php 
} else { 
?> <hr/><br/>
       <form method="post">
Enter Name:
    <input type="text" name="name" /><br/>
Enter Email:
    <input type="text" name="email" /><br/>
Comment:
    <input type="textarea" name="comment" /><br/>
<center><input type="submit" name="submit" value="Send" /></center>

<?php }; ?> 

</body>
</html>

if i use that code i get a HTTP 500 INTERNAL SERVER ERROR,
But if i use just this part of the code it all works fine????

<?php 
if ($_POST["email"]<>'') { 
	$ToEmail = 'my email
	$EmailSubject = 'subject
	$mailheader = "From: ".$_POST["email"]."\r\n"; 
	$mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
	$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
	$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>"; 
	$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>";
	$MESSAGE_BODY .= "comment".$_POST["comment"]."<br>";

mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");

<p>Thank you for your comment</p>

<?php 
} else { 
?> <hr/><br/>
       <form method="post">
Enter Name:
    <input type="text" name="name" /><br/>
Enter Email:
    <input type="text" name="email" /><br/>
Comment:
    <input type="textarea" name="comment" /><br/>
<center><input type="submit" name="submit" value="Send" /></center>

<?php }; ?>

any one got any ideas?
I am after creating a contact form but only for people who know the password.

Why did you not include actions in your form tags?

Like:

<form method="post" action="<?php echo $PHP_SELF; ?>">

action="<?php echo $PHP_SELF; ?>" calls the current php file.

Also, why not validate that a button was actually pushed? In your button tag you've got grammatical errors to begin with, and you should name your button.

<input type="submit value="login" />

Should resemble:

<input type="submit" name="buttonName" value="login" />

Like for your first section:

<?php
$user = 'admin';
$pass = 'admin';
if($_POST["buttonName"]){

if ($user != $_POST['username'] || $pass != $_POST['password']) { ?>

<form method="post" action="<?php echo $PHP_SELF; ?> >
Enter username:
<input type="text" name="username" /><br/>
Enter Password:
<input type="password" name="password" /><br/>
<center><input type="submit" name="buttonName" value="login" /></center>

<?php }
} ?>

By the way have you tried just the top of the code by it's lonesome? Try making the changes I mentioned. See if that helps anything.

Another thing I am wondering, the form will not show unless it obtains a value for $_POST to begin with. So try this instead:

<?php
$user = 'admin';
$pass = 'admin';
$status = 0;

if($_POST["buttonName"]){

if (($user != $_POST['username']) && ($pass != $_POST['password'])) 
$status = 0;
else 
status = 1; //accurate data

} //end if($_POST["buttonName"]) 

if ($status == 0) { ?>

<form method="post" action="<?php echo $PHP_SELF; ?>" >
Enter username:
<input type="text" name="username" /><br/>
Enter Password:
<input type="password" name="password" /><br/>
<center><input type="submit" name="buttonName" value="login" /></center>

<?php } ?>

By the way, you should use the and operator, not the or to validate that both pass and user name are valid. Also don't be afraid of brackets, so that code blocks are separated and there's no confusion in the operation to be performed. (line 8 above)

Hope this helps.

Oh, in the last code above, line 11, change status to $status.

:/

i never really got a answer for this, but i have just revisited and found this out,

<center><input type="submit value="login" /></center>

on line 20 is wrong i have missed 1 "
it should read

<center><input type="submit" value="login" /></center>

i cannot belive that i made a simple mistake and scraped the whole project,
and even that none of you spotted it,
for thoses of you who are still trying to work it out here

<center><input type="submit(" <- forgot to put that here) value="login" /></center>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.