PHP echo problem, plz help!

i am creating a login page, and i want it do if user input incorrect credentials, a message "in correct username/password" is displayed on the login page(without using a message box or alert). i tried darron_chapman's code(http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_23156476.html) but it seems doesn't work on mine. I got Undefined variable error!  anyone can help me with it?
<html>
	<head>		
		<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
		<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
		<title>Login</title>
	</head>
	<body>
		<form method="POST" action="log.php">
			<fieldset>
			<legend>Login</legend>
				UserName:
				<input name="UserName" type="text" size="10"  tabindex="1" style="font-size:12px;" />
            <br />                                       
				Password:
				<input name="Password" type="password" size="10"  tabindex="1" style="font-size:12px;" />	
			<br />
			<span id="error"><?php echo $message;?></span>
			<br /><input type="submit" value="Submit" name="submit" class="content"/><br />
		  </fieldset>
		</form>
	</body>
</html>

Open in new window

<?php
   session_start();
  
   if($_REQUEST['UserName'] == "wang" && $_REQUEST['Password'] == "1234"){
      $_SESSION['UserName'] = "wang";
      $_SESSION['Password'] = "1234";
      header("Location: index.php");
   }
   else{
      header("Location: login.php");
	  $message="Incorrect username/password";
   }
?>

Open in new window

qqchenAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
You're trying to share a variable between page, it's not possible. You may use a variable session here again.


<?php
   session_start();
  
   if($_REQUEST['UserName'] == "wang" && $_REQUEST['Password'] == "1234"){
      $_SESSION['UserName'] = "wang";
      $_SESSION['Password'] = "1234";
      header("Location: index.php");
   }
   else{
      header("Location: login.php");
	  $_SESSION['message'] = "Incorrect username/password";
          exit;
   }
?>

Open in new window

0
Amar BardoliwalaCommented:
Hello qqchen,


Please change your else part code to following.. and see if it helps.

Thanks.
else{
      $message="Incorrect username/password";
      header("Location: login.php?message=".$message);
	  
   }

Open in new window

0
qqchenAuthor Commented:
i tried both of your code, it looks still not work. T_T this is the error pic when i test this is the error pic when i test
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

leakim971PluritechnicianCommented:
you need to put session_start(); in login.php to use sessions
0
Amar BardoliwalaCommented:
Hello

in login.php, you should have following,

$message = $_GET["message"];

Thanks.
0
leakim971PluritechnicianCommented:
and for me of course (additonaly of the session_start() ) :
<span id="error"><?php echo $_SESSION['message'];?></span>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
Welcome to EE, qqchen.  Here are some ideas to make your use of this site more enjoyable and productive for you...

At EE, the experts exchange answers and advice for points.  If you look at the questions awaiting answers in this zone, you will see a lot of 500 point questions.  Your question is competing for the experts' attention among those high-point questions.  So as a matter of simple economics you might be able to envision which questions will get the experts' attention first.   Just a thought.

We are experts, but not mind readers.  Inquiries that are broad, vague and hypothetical may not get answers that are as succinct and effective as inquiries that have actual URLs, complete code examples, and clearly expressed questions.  "It doesn't work" is not an error message.  Whenever possible, please provide the inputs and tell us what you want for the outputs.  Sometimes the right answer is, "Don't do that -- it doesn't work that way."

If you want us to be able to share working code, we need you to show us where you have put your test data.  If you have no test data, please create some.  We do not want you to post "live" passwords and such.  Instead, please set up a testbed and show us the links to that, instead of the live data.

We answer questions and provide teaching examples, but we cannot build your applications for you.  If you do not understand the basics of computer science and the programming languages involved in your applications, you might be better off to hire a developer.  Often a great deal of trial and error, plus a depth of knowledge and background information is necessary to get a piece of an application working.  The experts will try to help, but sometimes the only reasonable answer is, "Please read the fine manuals" or "Don't waste your time -- hire a professional developer."

All of us who have been at EE for a while have seen questions like, "How do I do 'X' in 'Y' language, and by the way, I do not know anything about 'Y' language."  For some reason we never see anyone ask, "I want to play a piano sonata, and by the way, I have never taken piano lessons."  It is hardly a sin if you do not know a particular programming language -- I do not know most of them -- but it is not reasonable to expect that you will learn a programming language by asking questions in an online forum, any more than you could learn to play the piano by asking questions in an online forum.  Instead your best question might be, "What are good learning resources to get a foundation in 'Y' language?"  We are glad to help with that.

This article teaches the principles behind what you are trying to do:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391-PHP-login-logout-and-easy-access-control.html

All the best, ~Ray
0
qqchenAuthor Commented:
Thank u for helping.. it works now!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.