--- In [email protected], "yogeshromantic" <[EMAIL PROTECTED]>
wrote:
> the submit button the data should update in Mysql database table. but
> i want to validate the textfield if it Null/Blank proper message
> should display on the screen
This is how I do it, and I suspect you'll get a variety of answers,
all very similar to this.
-------
<?php
// this form goes in the header of the file containing
// the form. The form action should point to the same
// file as the form as well.
// so...
// user has submitted the form
if ((is_array($_POST)) && isset($_POST['submit'])) {
if (!isset($_POST['name']) {
$err = 1; $errmsg[] = "Please enter your name";
} else {
$name = addslashes($_POST['name']);
}
// similarly, any required field can be handled this way
// you probably want to ensure that values are entered
// properly by checking them against regular expressions
// ... that isn't covered here... :-)
if (!isset($_POST['address'])) {
$err = 1; $errmsg[] = "Please enter your address";
} else {
$address = addslashes($_POST['address']);
}
if (!isset($_POST['phone'])) {
$err = 1; $errmsg[] = "Please enter your phone number";
} else {
$phone = $_POST['phone'];
}
// if all fields have values (i.e., $err does not equal 1)
// then go on and process the form
// my query string is a little odd -- I use the excellent
// EZ_SQL class by Justin Vincent (http://php.justinvincent.com)
// to handle my queries
if (!$err) {
$db->query("insert into table_name (col1, col2, col3) values
('$name', '$address', '$phone')");
}
}
// assuming the script above is in the header of the same file
// containing the form, you can simply place the following
// directly above your form. I like to create a "warning" style
// and place the message below inside a div with that class
// assigned to create a different background color, red warning
// text, etc. Something to make it stand out...
if ($err == 1) {
echo '<div class="warning">';
echo '<p><strong>There were problems with your
submission:</strong></p>';
echo '<ul>';
foreach ($errmsg as $erm) {
echo '<li>' . $erm . '</li>';
}
echo '</ul></div>';
}
// and this will echo out any error messages thrown back
// by the script above. Let's say user didn't fill out
// any of the required form fields:
//
// There was a problem with your submission:
// * Please enter your name
// * Please enter your address
// * Please enter your phone number
?>
--------
Hope that helps!
-Bob
Community email addresses:
Post message: [email protected]
Subscribe: [EMAIL PROTECTED]
Unsubscribe: [EMAIL PROTECTED]
List owner: [EMAIL PROTECTED]
Shortcut URL to this page:
http://groups.yahoo.com/group/php-list
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/php-list/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/