Strange PHP setup issues

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
lyleyboy
Forum Commoner
Posts: 27
Joined: Sat Mar 18, 2006 5:05 am
Location: Birmingham, UK

Strange PHP setup issues

Post by lyleyboy »

I have a weird (or maybe not) issue.

I'm trying to do a really basic bit of form validation. I'm using a friends server as it's his site. I've tested this on mine 1and1 in the UK. It works fine. Tried it on his, fasthosts and it fails.

The crux of the problem seems to be that I am setting a variable inside an if statement.
If I then try to use the variable outside the if I get an error undefined variable. I have even tried to define the variable as a dummy value before the if statement but I get the same error.

My code looks like this

Code: Select all

if ($_POST['name']<""){
    $errors = "1";
    $name_error = "You did not enter your name!";
}
 
 
if ($errors == "1") {
echo "Errors";
}
The error onscreen is below. Line numbers will be wrong as I have not published all the rubbish here.

Code: Select all

Notice: Undefined variable: errors in E:\domains\n\nicholaskirtonphotography.co.uk\user\htdocs\contact_process.php on line 35

Can anyone help as I am about to move the site to a different server.
P.s. Fasthosts seem to think this is fine.
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: Strange PHP setup issues

Post by panic! »

Code: Select all

if (empty($_POST['name'])){
     $errors = "1";
     $name_error = "You did not enter your name!";
   }
  
  
 if (isset($errors)) {
 echo "Errors";
 }
Post Reply