Display errors

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Display errors

Post by ddragas »

Hi

How to display errors in same page where form is.
Errors are validation if user has input certan fields of form

exsample:
if ($name="" echo "You didn't input your name";
if ($email="" echo "You didn't input your email";

etc.....
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

Code: Select all

<?php
if (empty($username_text_field_name)) {
echo "error, fill in username";
}

etc

and use $_SERVER['PHP_SELF']; to get it to stay on the same page, but just send it to a different page to validate.  I dont get the jist of PHP_SELF, when you can create another small file and go thru less hassel.
?>
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

ok
and how to display all errors together.

Should I put all errors in one variable?
example

$error='
if (empty($username_text_field_name)) {
echo "error, fill in username". "<br>\n";
}
if (empty($Last_name)) {
echo "error, fill in last name". "<br>\n";
}
if (empty($email)) {
echo "error, fill in email". "<br>\n";
}'

and then sendit to first page where form is with
$_POST['error'];
and later
echo $error;?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I handle form processing in the page with the form, until everything is valid, then it redirects or whatever to the "success" page.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

turn the errors into an array

if (condiction) {
$error[] = "error 1";
}

if (condiction2) {
$error[] = "error 2";
}

etc

foreach() then
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

tim wrote:turn the errors into an array

if (condiction) {
$error[] = "error 1";
}

if (condiction2) {
$error[] = "error 2";
}

etc

foreach() then
Whats wrong with just adding a string?

Code: Select all

$errors .= "You didn't enter a username!<br />\n";
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

that would be the simpler route to take

But i like mine better, :P
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Well.. uh.. I like mine more!

End of discussion.

I win.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

okay
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

thank you guys
Post Reply