We help IT Professionals succeed at work.

How to Display Error Message While Downloading Report

Opeyemi AbdulRasheed
on
93 Views
Last Modified: 2018-09-09
Hello Experts!

I have a php page where students enter information to check their results.
See here

I want to display relevant error message on the same page when wrong info is entered. Currently, I'm using error_reporting(0);.
The result is in PDF format.

Please use following to get accurate result:
Class:                       SS 1A
Session:                  2018/2019
Term:                      1st Term
Adminssion No:    GSS/0001
Password:              abc (could be any string)

And use random data to get what I'm taking about.

Bellow is part of the codes:

myForm:
<form id="resultForm" action="terminal_result.php" method="POST">
                        <!--Form with header-->
                        <div class="card wow fadeIn white" data-wow-delay="0.3s">
                            <div class="card-body">
                                <!--Header-->
                                <div class="form-header blue-gradient">
                                    <h3><i class="fa fa-download mt-2 mb-2"></i> Check Result</h3>
                                </div>
                                <div id="error"></div>
                                <!--Body-->
                                <div>                                    
                                    <select name="class_name" id="class_name" class="mdb-select colorful-select dropdown-info" required="required">
                                        <option value="" disabled selected>Choose Class</option>
                                        <?php echo fill_class_box($conn); ?>
                                    </select>
                                </div>
                                <div>                                    
                                    <select name="session" id="session" class="mdb-select colorful-select dropdown-info" required="required">
                                        <option value="" disabled selected>Choose Year of Result</option>
                                        <?php echo fill_session_box($conn); ?>
                                    </select>
                                </div>
                                <div>                                    
                                    <select name="term" id="term" class="mdb-select colorful-select dropdown-info" required="required">
                                        <option value="" disabled selected>Choose Term</option>
                                        <?php echo fill_term_box($conn); ?>
                                    </select>
                                </div>
                                
                                <div class="md-form">
                                    <i class="fa fa-user prefix grey-text"></i>
                                    <input type="text" name="student_id" id="student_id" class="form-control" autocomplete="off" required="required">
                                    <label for="student_id">Admission No</label>
                                </div>

                                <div class="md-form">
                                    <i class="fa fa-lock prefix grey-text"></i>
                                    <input type="password" name="password" id="password" class="form-control" required="required">
                                    <label for="password">Password</label>
                                </div>
                                <div class="text-center">
                                    <button type="submit" name="download_result" id="download_result" class="btn blue-gradient btn-lg">Submit</button>
                                
                                </div>
                            </div>
                        </div>
                    </form>

Open in new window


The script:
<?php
require('../../fpdf.php');
require('../conn.php');
error_reporting(0);

function clean($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}

$stu_id = clean($_POST['student_id']);
$class = clean($_POST['class_name']);
$session = clean($_POST['session']);
$term = clean($_POST['term']);

//biodata
$biodata = $conn->prepare("SELECT * FROM ... WHERE Student_ID = ? ");
$biodata->bind_param("s", $stu_id);
$biodata->execute();
$report = $biodata->get_result();
$student = $report->fetch_object();

//date in yyyy-mm-dd format; or it can be in other formats as well
  $birthDate = $student->Date_Of_Birth;
  //explode the date to get month, day and year
  $birthDate = explode("-", $birthDate);
  //get age from date or birthdate
  $age = (date("md", date("U", mktime(0, 0, 0, $birthDate[2], $birthDate[1], $birthDate[0]))) > date("md") ? ((date("Y") - $birthDate[0]) - 1) : (date("Y") - $birthDate[0]));
  $age_year = "".$age." years";

//attendance and comment
$attendance_comment = $conn->prepare("SELECT ... FROM ... LEFT JOIN ... ON ... WHERE Student_ID = ? AND Class_Name = ? AND Session = ? AND Term = ?");

//and so on

Open in new window


Please help.
Comment
Watch Question

Consultant
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Superb! I'll check it out now.
Thank you so much. I implemented your suggestion and it really makes sense.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.