2 Replies - 194 Views - Last Post: 31 December 2018 - 03:15 PM Rate Topic: -----

#1 testmetestyou   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 76
  • Joined: 19-July 16

why doesnt show my error messages

Posted 30 December 2018 - 10:11 PM

Why it doesnt show my error messages?
But if i use only if(isset($_POST['Submit'])){} it works with showing my error messages.. but then it uploads image but other inputs are empty and showing errors..

How to do and what to do?

My code:

if( isset($_POST['Submit'])
    && isset($_POST['name'])
    && trim($_POST['name']) != ''
    && isset($_POST['manager'])
    && trim($_POST['manager']) != ''
    && isset($_FILES['logo'])
    && $_FILES['logo']['size'] > 0
    && isset($_POST['csrf_i'])
    && isset($_SESSION['csrf_i'])
    && $_POST['csrf_i'] == $_SESSION['csrf_i'] ){
    
    $path = "../img/logo/";
    $file = $_FILES['logo']['name'];
    $handle = new Upload($_FILES['logo']);
    if ($handle->uploaded) {
    $handle->file_new_name_body = getToken(4) . date("dmY") . getToken(4) . date("Hi").getToken(7);
    $handle->file_max_size = '4194304'; //4MB
    $handle->Process($path); 
    }

    $logo = "img/logo/".$handle->file_dst_name;
    $name    = $_POST['name'];
    $manager = $_POST['manager'];

    $validator = new Validator();

    $validator->set('Team name', $name)->min_length(2)->is_required();
    $validator->set('Manager', $manager)->min_length(2)->is_required();
    $validator->set('Logo', $file)->is_selected();

    if ($validator->validate()){
        try {
            $insert_stmt=$db->prepare('INSERT INTO teams(name, logo, manager) VALUES (:name, :logo, :manager)'); //sql insert query     
            $insert_stmt->bindParam(':name',$name); 
            $insert_stmt->bindParam(':logo',$logo);
            $insert_stmt->bindParam(':manager',$manager);

            if($insert_stmt->execute()){
                echo "Team created....."; //execute query success message
                header("refresh:3;teams.php"); //refresh 3 second and redirect to teams.php page
            }
            exit;
        } catch(PDOException $e) {
            echo $e->getMessage();
        }
    }else{
        $errors = $validator->get_errors();
        foreach ($errors as $err => $error) {
            foreach ($error as $key => $value) {
                echo $value . "<br>";
            }
        }
    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: why doesnt show my error messages

#2 andrewsw   User is online

  • Stealth IT
  • member icon

Reputation: 6745
  • View blog
  • Posts: 27,775
  • Joined: 12-December 12

Re: why doesnt show my error messages

Posted 31 December 2018 - 03:31 AM

You have about 10 conditions so it is likely at least one fails. Break it down and print stuff out to discover which, if any, fails. Basic debugging.
Was This Post Helpful? 1
  • +
  • -

#3 benanamen   User is offline

  • D.I.C Head

Reputation: 34
  • View blog
  • Posts: 234
  • Joined: 28-March 15

Re: why doesnt show my error messages

Posted 31 December 2018 - 03:15 PM

Grouping all your checks is lazy and difficult to debug as you are now finding out. Create individual checks, put any errors into an error array and then loop over the error array if it is not empty and display the specific error messages.

Do not output internal system errors to the user. That info is only good to hackers and useless to the user.

Depending on a button to be submitted in order for the script to work will completely fail in certain cases. You need to check the REQUEST METHOD instead.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1