SiteExperts.com Logo Home | Community | Developer's Paradise
User Groups | Site Tools | Site Information | Search
 Main Menu
 Forums
SiteExperts.com Forums
All Discussions

SiteExperts Feedback
The Lounge
Dynamic HTML
Site Design/ Critiques
HTML and CSS
XML Technologies
The Wireless Internet
Internet Explorer
Microsoft .NET
The Server
Technical Support

Sponsored Links

User Groups : Forums : SiteExperts : The Lounge :

Previous DiscussionNext Discussion
 php question

I am having trouble with using a hidden field the actual code is really simple:

<?php session_start();
 echo $_POST['error'];

?>
<html>
<body>
<table border ="0" cellspacing ="0" cellpadding="0" style="margin-left:25px;"> <!-- login table -->
    <tr><td colspan="2"><h1>Login Details:</h1></td></tr>
    <tr><td colspan ="2"><img src="spacer.gif" height="15px"</td></tr>
<tr>
  <td style ="font-size:16pt; font-family:Arial;">
  <form ACTION="hidden.php" Method="POST">
  <label for="uname">
  Username:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  </label>
  </td>
  <td>
  <input id="uname"  style="height:40px;padding-top:10px; font-size:16px;" type ="text" Name="userName" />
  </td>
  <tr><td colspan ="2"><img src="spacer.gif" height="15px"/></td></tr>
</tr>
<tr>
  <td style ="font-size:16pt; font-family:Arial;">
  <label for="pass">
   Password:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  </label>
  </td>
  </td>
  <td>
  <input  type ="password" id="pass" style="height:40px;padding-top:10px;font-size:16px;" Name="password"/>
  <a href="forgotpass.htm" style="font-size:16pt; text-decoration:none;">Forgotten your Password</a>
  </td>
</tr>
<tr>
  <td colspan="2">
 <input type="hidden" name="error" value="big" />
  <input type="submit" value="Log In"/ style="font-size:16pt; font-family:Arial;color:white;"/>
  </form>
  </td>
</tr>
<tr>
  <td><img src="spacer.gif" height="15px"/></td>
  <td style="font-size:16pt;" align="right">Please enter your username and password</td>
</tr>
<tr>
 <td></td>
 <td><?php echo $_POST['error']; ?></td> <!--error tag -->
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
<?php
$_POST['error'] = "Hello"; 
    echo $_POST['error'];
?>
when I click the submit  button the word big comes out onto the screen as expected.This is becasue it is hard wired into the value filed of the hidden field.

 

However if I change it to <input type="hidden" name="error" value="<?php echo $_POST['error'];?>" /> it wont set it and prints a blank

if I try setting a variable and putting that as the echo value it still prints a blank..?

As you can see at the bottom of the page the last line of code sets the post variable to hello but that is not printed after the submit button is clicked..?

Started By Laurencek on Feb 22, 2010 at 4:23:16 AM

1 Response(s) | Reply

Earlier Replies | Replies 1 to 1 of 1 | Later Replies
Monte on Feb 22, 2010 at 6:10:27 PM (# 1)
This message has been edited.

Remember...PHP is executed on the server side.

Therefore,



will always return blank, because the initial value of your hidden value is blank.

$_POST['error']; essentially says "Find the posted value of 'error' and save it to $_POST".

And, since your input type is initially blank, that's exactly what happens.

So, your code actually functions as it should, although your intention is not for it to function that way.


Earlier Replies | Replies 1 to 1 of 1 | Later Replies

To respond to a discussion, you must first logon.

If you are not registered, please register yourself to become a member of the SiteExperts.community.

User Name
Password
Copyright 1997-2004 InsideDHTML.com, LLC. All rights reserved.