Testing for an empty file field
Posted: Thu Nov 06, 2003 5:33 pm
Hello.
My code seems to be behaving oddly in terms of if's...(take a look):
The problem is, when an avatar is not submitted (I test it using if ($_FILES['avatar']['name'] != "" ) { do stuff} ), it returns "Your avatar is too large. Please go back and choose another one". Something is terms of if's and else's is messed up, I need another set of eyes, I know it's some dumb error. If an avatar is entered, everything works fine.
I apologize for the messy code.
Thanks for the help!
My code seems to be behaving oddly in terms of if's...(take a look):
Code: Select all
<?php
//check if an avatar was entered
if ($_FILES['avatar']['name'] != "" ) {
$avinfo=getimagesize($_FILES['avatar']['tmp_name']);
if ($avinfo['0'] < 41 && $avinfo['1'] < 41) {
move_uploaded_file($_FILES['avatar']['tmp_name'], 'avatars/'.$_FILES['avatar']['name']); }
//check for correct input
if ($name == "" || $email == "")
{
echo "Something is wrong. Please go back and make sure you have filled in all required boxes.";
//HTML redirection
?><meta http-equiv="refresh" content="3;url=profile.php"><?php
}
else
{
$avname=$_FILES['avatar']['name'];
if ($pass2=="") {
$query="UPDATE users SET name='$name', email='$email', icq='$icq', msn='$msn', aim='$aim', location='$location', greeting='$greeting', avatar='$avname' WHERE id='$id'"; }
elseif ($pass2=="" && $avname=="") {
$query="UPDATE users SET name='$name', email='$email', icq='$icq', msn='$msn', aim='$aim', location='$location', greeting='$greeting' WHERE id='$id'"; }
elseif ($avname=="") {
$pass2=md5($pass2);
$query="UPDATE users SET name='$name', password='$pass2', email='$email', icq='$icq', msn='$msn', aim='$aim', location='$location', greeting='$greeting' WHERE id='$id'"; }
else {
$pass2=md5($pass2);
$query="UPDATE users SET name='$name', password='$pass2', email='$email', icq='$icq', msn='$msn', aim='$aim', location='$location', greeting='$greeting', avatar='$avname' WHERE id='$id'"; }
$result=mysql_query ($query, $db) or die (mysql_error());
echo "You just altered your profile. Please wait...";
//HTML redirection
?>
<meta http-equiv="refresh" content="3;url=index.php">
<?php
} }
else {
echo "Your avatar is too large. Please go back and choose another one.";
?><meta http-equiv="refresh" content="3;url=profile.php"><?php } ?>I apologize for the messy code.
Thanks for the help!