Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- Displaying data from a form


Adam5000 - 3:41 am on Sep 26, 2010 (gmt 0)


Greetings all

I'm trying to validate user input into a form by using PHP. The data entered into the fields will be put into a MySql database. And I read this on the W3school's website.

"You should consider server validation if the user input will be inserted into a database. A good way to validate a form on the server is to post the form to itself, instead of jumping to a different page. The user will then get the error messages on the same page as the form. This makes it easier to discover the error."

So I'm trying to post the form to itself and see what the page looks like with both the form and a message on it.

But I'm not having any luck. Below is the code I'm using.

Help!

<html>
<head>
<title>Display field</title>
</head>

<body>

<?php

function display_field()
{
echo $_POST["user_name"];
}

?>

<form action="display_field.php" method="post">

Username: <input type="text" name="user_name">
<input type="submit" value="Submit" onClick="display_field()">

</form>

</body>
</html>


Thread source:: http://www.webmasterworld.com/php/4207011.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com