Jump to content

Recommended Posts

Hi, I have a user edit page that I cannot seem to get working correctly. We recently set out to add the addition of a avatar to our page. So... We edited the code and everything is working great for everyone but me. 

 

 

When I press submit on the form it sends me to a internal server error page instead of preloading the current page I am on. Everything that should get updated still does the only problem is the page will not load properly afterwards. I am at a complete wall and dont know where else to look. 

 

 

I was able to find out that if I remove a specific block of code the the page will reload but the picture will not update. 

 

1. Picture wont upload but page will reload. 

 

2. Picture will upload as expected but page doesnt reload correctly. 

 

Complete page code. 

<?php
error_reporting(0);

require('includes/application_top.php');
require('includes/classes/crypto.php');


$crypto = new phpFreaksCrypto;



include('includes/classes/class.formvalidation.php');

include('includes/classes/class.phpmailer.php');



if (isset($_POST['submit'])) {

   $my_form = new validator;

   $mail = new PHPMailer();

   if($_POST['password'] !== ''){

   if($my_form->checkEmail($_POST['email'])) { // check for good mail

            

      if ($my_form->validate_fields('firstname,lastname,email,password')) { // comma delimited list of the required form fields

         if ($_POST['password'] == $_POST['password2']) {

            $allowedExts = array("gif", "jpeg", "jpg", "png");

            $extension = end(explode(".", $_FILES["img"]["name"]));

            if ((($_FILES["img"]["type"] == "image/gif")
            || ($_FILES["img"]["type"] == "image/jpeg")
            || ($_FILES["img"]["type"] == "image/jpg")
            || ($_FILES["img"]["type"] == "image/pjpeg")
            || ($_FILES["img"]["type"] == "image/x-png")
            || ($_FILES["img"]["type"] == "image/png"))
            && ($_FILES["img"]["size"] < 3145728)
            && in_array($extension, $allowedExts))
            {
               if ($_FILES["img"]["error"] <= 0)
               {
                $files = glob("upload/$user->userID.*");
               foreach ($files as $file) {
               unlink($file);
               }
                  move_uploaded_file($_FILES["img"]["tmp_name"], "upload/" . $user->userID.'.'.$extension);
               }
            }

            $salt = substr($crypto->encrypt((uniqid(mt_rand(), true))), 0, 10);

            $secure_password = $crypto->encrypt($salt . $crypto->encrypt($_POST['password']));

            $sql = "update " . $db_prefix . "users ";

            $sql .= "set password = '".$secure_password."', salt = '".$salt."', firstname = '".$_POST['firstname']."', lastname = '".$_POST['lastname']."',  email = '".$_POST['email']."',  template_name = '".$_POST['template_name']."' ";

            $sql .= "where userID = " . $user->userID . ";";

            //die($sql);

            mysql_query($sql) or die(mysql_error());

            

            //set confirmation message
            header('Location: index.php');

         } else {

            $display = '<div class="responseError">Passwords do not match, please try again.</div><br/>';

         }

      } else {

         $display = str_replace($_SESSION['email_field_name'], 'Email', $my_form->error);

         $display = '<div class="responseError">' . $display . '</div><br/>';

      }

   } else {

      $display = '<div class="responseError">There seems to be a problem with your email address, please check.</div><br/>';

   }

}

        elseif ($_post['password'] == ''){
        if($my_form->checkEmail($_POST['email'])) { // check for good mail

 $allowedExts = array("gif", "jpeg", "jpg", "png");

            $extension = end(explode(".", $_FILES["img"]["name"]));

            if ((($_FILES["img"]["type"] == "image/gif")
            || ($_FILES["img"]["type"] == "image/jpeg")
            || ($_FILES["img"]["type"] == "image/jpg")
            || ($_FILES["img"]["type"] == "image/pjpeg")
            || ($_FILES["img"]["type"] == "image/x-png")
            || ($_FILES["img"]["type"] == "image/png"))
            && ($_FILES["img"]["size"] < 3145728)
            && in_array($extension, $allowedExts))
            {
               if ($_FILES["img"]["error"] <= 0)
               {
                $files = glob("upload/$user->userID.*");
               foreach ($files as $file) {
               unlink($file);
               }
                  move_uploaded_file($_FILES["img"]["tmp_name"], "upload/" . $user->userID.'.'.$extension);
               }
            }

                                               
                if ($my_form->validate_fields('firstname,lastname,email, template_name')) { // comma delimited list of the required form fields
                        if ($_POST['password'] == '') {
                                $sql = "update " . $db_prefix . "users ";
                                $sql .= "set firstname = '".$_POST['firstname']."', lastname = '".$_POST['lastname']."', email = '".$_POST['email']."', template_name = '".$_POST['template_name']."' ";
                                $sql .= "where userID = " . $user->userID . ";";
                                //die($sql);
                                mysql_query($sql) or die(mysql_error());
                               
                                //set confirmation message
                                header('Location: index.php');
                        } else {
                                $display = '<div class="responseError">Passwords do not match, please try again.</div><br/>';
                        }
                } else {
                        $display = str_replace($_SESSION['email_field_name'], 'Email', $my_form->error);
                        $display = '<div class="responseError">' . $display . '</div><br/>';
                }
        } else {
                $display = '<div class="responseError">There seems to be a problem with your email address, please check.</div><br/>';
        }
        }
        else {
                $display = '<div class="responseError">You broke all the things</div><br/>';
                }
                }

include('includes/header.php');



$sql = "select * from " . $db_prefix . "users where userID = " . $user->userID;

$query = mysql_query($sql);

if (mysql_num_rows($query)) {

   $result = mysql_fetch_array($query);

   $firstname = $result['firstname'];

   $lastname = $result['lastname'];

   $email = $result['email'];

   $template_name = $result['template_name'];

}



if (!empty($_POST['firstname'])) $firstname = $_POST['firstname'];

if (!empty($_POST['lastname'])) $lastname = $_POST['lastname'];

if (!empty($_POST['email'])) $email = $_POST['email'];

if (!empty($_POST['template_name'])) $template_name = $_POST['template_name'];

?>

   <h1>Edit User Account Details</h1>

   <?php if(isset($display)) echo $display; ?>

   <form action="user_edit.php" method="post" name="edituser" enctype="multipart/form-data">   

      <fieldset>

      <legend style="font-weight:bold;">Enter User Details:</legend>

         <table cellpadding="3" cellspacing="0" border="0">

           <?php if ($isGuest) { ?>
           
        <tr><td>First Name:</td><td><input type="text" name="firstname" value="<?php echo $firstname; ?>" readonly></td></tr>
            <tr><td>Last Name:</td><td><input type="text" name="lastname" value="<?php echo $lastname; ?>" readonly></td></tr>
            <tr><td>Email:</td><td><input type="text" name="email" value="NULL" size="30" readonly></td></tr>

           <?php } else { ?>

            <tr><td>First Name:</td><td><input type="text" name="firstname" value="<?php echo $firstname; ?>"></td></tr>
            <tr><td>Last Name:</td><td><input type="text" name="lastname" value="<?php echo $lastname; ?>"></td></tr>
            <tr><td>Email:</td><td><input type="text" name="email" value="<?php echo $email; ?>" size="30"></td></tr>
           
           <?php } ?>
            
            <tr><td>Favorite Team:</td><td><?php $template =$result['template_name'];?>
                
             <select name="template_name" >
             
<option name="template_name" value="<?php echo "$template_name"; ?>">Choose your team template</option>
<option value="main">NFL</option>
<option value="ARI">Cardinals</option>
<option value="ATL">Falcons</option>
<option value="BAL">Ravens</option>
<option value="BUF">Bills</option>
<option value="CAR">Panthers</option>
<option value="CHI">Bears</option>
<option value="CIN">Bengals</option>
<option value="CLE">Browns</option>
<option value="DAL">Cowboys</option>
<option value="DEN">Broncos</option>
<option value="DET">Lions</option>
<option value="GB">Packers</option>
<option value="HOU">Texans</option>
<option value="IND">Colts</option>
<option value="JAX">Jaguars</option>
<option value="KC">Chiefs</option>
<option value="MIA">Dolphins</option>
<option value="MIN">Vikings</option>
<option value="NE">Patriots</option>
<option value="NO">Saints</option>
<option value="NYG">Giants</option>
<option value="NYJ">Jets</option>
<option value="OAK">Raiders</option>
<option value="PHI">Eagles</option>
<option value="PIT">Steelers</option>
<option value="SD">Chargers</option>
<option value="SEA">Seahawks</option>
<option value="SF">49ers</option>
<option value="STL">Rams</option>
<option value="TB">Buccaneers</option>
<option value="TEN">Titans</option>
<option value="WAS">Redskins</option>
             </select></td></tr>
           
            <tr><td> </td></tr>

           <?php if ($isGuest) { ?>
            
           <?php } else { ?>
            <tr><td>New Password:</td><td><input type="password" name="password"></td></tr>
            <tr><td>Confirm Password:</td><td><input type="password" name="password2"></td></tr>
            
           <?php } ?> 
            <tr><td> </td></tr>
            <tr><td>Avatar:</td><td><input type="file" name="img" id="img" <?php if ($isGuest) { ?> disabled <?php } ?>></td></tr>
            
            <tr><td> </td><td>
<?php
   $avatars = glob("upload/$user->userID.*");
   if(!empty($avatars)) {
   $avatar = $avatars[0];
  
   echo '<img style="width:20%;" src="'.$avatar.'">';
   echo '<p>**Note Image must be smaller than 3MB.</p>';
   echo '<input type="submit" name="submit" value="Submit"></td></tr>';
   echo '</table></fieldset></form></table></fieldset>';
   include('includes/footer.php'); 
   
   } else {
   $avatar = 'upload/default.jpg';
   echo '<img style="width:20%;" src="'.$avatar.'">';
   echo '<p>No avatar set, please upload one.<br>Image must be smaller than 3MB.</p>';
   echo '<input type="submit" name="submit" value="Submit"></td></tr>';
   echo '</table></fieldset></form></table></fieldset>';
    
   include('includes/footer.php');
   }

require 'includes/correctImageOrientation.php'; correctImageOrientation('upload/'); 
?>

If I remove  this specific piece of code then I have the case where the page loads fine but picture wont upload.

$allowedExts = array("gif", "jpeg", "jpg", "png");

            $extension = end(explode(".", $_FILES["img"]["name"]));

            if ((($_FILES["img"]["type"] == "image/gif")
            || ($_FILES["img"]["type"] == "image/jpeg")
            || ($_FILES["img"]["type"] == "image/jpg")
            || ($_FILES["img"]["type"] == "image/pjpeg")
            || ($_FILES["img"]["type"] == "image/x-png")
            || ($_FILES["img"]["type"] == "image/png"))
            && ($_FILES["img"]["size"] < 3145728)
            && in_array($extension, $allowedExts))
            {
               if ($_FILES["img"]["error"] <= 0)
               {
               $files = glob("upload/$user->userID.*");
               foreach ($files as $file) {
               unlink($file);
               }
                  move_uploaded_file($_FILES["img"]["tmp_name"], "upload/" . $user->userID.'.'.$extension);
               }
            }

 I attached the include file that I am using in case that is helpful as well. 

 

I am using php5.4 fastCGI on a godaddy server(plesk windows hosting) 

correctImageOrientation.php

Edited by reloadmvp

Did you check the permissions for files in the upload directory matching the spec that is being unlinked?

 

Is there possibly a file there that has different perms, such that it can't be removed?

 

Are warnings turned on, and are any warnings being generated?

 

There are many things that could be going wrong, but if I understand you correctly, this code works for other users, just not for you?

 

For that reason, you want to check your assumptions by making a test account or several and determining if it is local to your workstation environment or your specific user.

 

What else could be different about your account?

 

What is the nature of $user->userID? Is this a number or a string?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.