Current location: Hot Scripts Forums » Programming Languages » PHP » Showing errors on a page


Showing errors on a page

Reply
  #1 (permalink)  
Old 03-16-04, 08:25 AM
pernaveikko pernaveikko is offline
New Member
 
Join Date: Mar 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Showing errors on a page

Hi!

How can I show errors on an input page when a user has not filled in all the required fields?

On a page there's a message, for instance, "Please, go back and enter your email address".

When the user goes back to the preceeding page I would like to show the missing field with a red arrow or something. Obviously, the information has been given already but I'd like to make it more visible to them.

Another question:

How can I divide search results to many pages? For example, if there are 100 results I'd need to put them to five pages with 20 results each.

Cheers.
Reply With Quote
  #2 (permalink)  
Old 03-16-04, 10:22 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
you need to check if the variables posted are filled with either empty() or ! ..
something like this :
PHP Code:

//simple form with name,email and comments ..

$name trim($_POST['name']);
$email trim($_POST['email']);
$comment trim($_POST['comments']);

if (!
$name) {
  echo
'You did not fill "Name" field!<br />';
}
if (!
$email) {
  echo
'You did not fill "E-mail" field!<br />';
}
if (!
$comment) {
  echo
'You did not fill "Comments" field!<br />';

this is a method, but there is another one .. Blaw's one
PHP Code:

foreach ($_POST as $field => $value) {

  if (!
$value) {
    echo 
$field ' was not filled! please go back and fill it<br />';
}

as for the second question..
you can do this with LIMIT in mysql_query() ..
example:
Code:
SELECT * FROM table_1 LIMIT 0, 10;
this LIMIT will start fetching 10 records from record number zero!
how can you tell the LIMIT to fetch the next 10 in php?! use a GET var in your url .. something like this:
PHP Code:

if (!isset($_GET['startrow'])) {

  
$start 0;
} else {
  
$start $_GET['startrow'];
}

$fetch mysql_query("SELECT * FROM table_1 LIMIT $start, 10"); 
the url should look like this :
page.php?startrow=NUMBER_HERE
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]

Last edited by NeverMind; 03-16-04 at 10:25 AM.
Reply With Quote
  #3 (permalink)  
Old 03-16-04, 11:40 AM
pernaveikko pernaveikko is offline
New Member
 
Join Date: Mar 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
you need to check if the variables posted are filled with either empty() or ! ..
something like this :


Yeah, that's exactly what I've done at the moment but I'd just like to make it a bit more better. When the user goes back to the page I would like to highlight the missing field.

Or it would be even better if there wasn't an error page at all but the same page was loaded with the missing fields highlighted...

Thanks for the other question as well, it looks straight forward enough, I'll try and code that.
Reply With Quote
  #4 (permalink)  
Old 03-16-04, 02:04 PM
Addict's Avatar
Addict Addict is offline
Newbie Coder
 
Join Date: Nov 2003
Location: Ohio
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
I would suggest JavaScripting for that. Why bother with submitting a form if the fields aren't filled in? Since JavaScript is client side it will save that step.

You can also do the highlighting like you mentioned. I'll try to dig up a good example.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically refresh page after page load failure jdugger JavaScript 3 08-05-10 09:16 AM
Classified Ads skipper23 Perl 3 11-22-05 02:22 AM
Help with saving a page (XMLHTTP?) ziadn JavaScript 0 01-15-04 01:38 AM
Classified Ads skipper23 Perl 2 12-30-03 03:43 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM


All times are GMT -5. The time now is 10:19 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.