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
D_zone
Forum Newbie
Posts: 14 Joined: Mon Nov 02, 2009 9:22 am
Post
by D_zone » Mon May 07, 2012 10:57 am
So my problem is this, I got a registration form BUT every time I got an error it display it above the <h1> Registration </h1> title I have in my form. My goal is to place the errors Below the Registration title. I have a class called register and the function that display errors in it. This is the code;
Code: Select all
if(isset($_POST['submit']))
{
include_once('register.php');
$register = new Register();
if($register->process())
header("Location:http://www.google.com");
else
$error_mess = $register->display_errors();
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Registration</title>
<link rel="stylesheet" type="text/css" href="../style.css" />
<body>
<h1> Registration </h1>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
</div>
<?php
if ($error_mess) { echo $error_mess ;}
?>
...The rest of the form HTML code...
function display_errors
Code: Select all
public function display_errors()
{
echo "<h3>Errors</h3>";
foreach($this->errors as $key=>$value)
echo $value."<br>";
}
Thank you in advance for future replies
Last edited by
D_zone on Mon May 07, 2012 4:01 pm, edited 1 time in total.
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Mon May 07, 2012 11:12 am
display_errors is broken. It echoes errors instead of returning them.
D_zone
Forum Newbie
Posts: 14 Joined: Mon Nov 02, 2009 9:22 am
Post
by D_zone » Mon May 07, 2012 4:00 pm
Hi Celauran, thank you for replying, I fixed the broken function by adding a return variable.
Code: Select all
public function display_errors()
{
$errorx = "<h3>Errors</h3>";
foreach($this->errors as $key=>$value)
$errorx .= $value."<br>";
return $errorx ;
}
tom12j
Forum Newbie
Posts: 1 Joined: Tue May 08, 2012 7:02 am
Post
by tom12j » Tue May 08, 2012 7:05 am
This is not a good programming practice. Why you are not using exception handling?