Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6605471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:17:17+00:00 2026-05-25T19:17:17+00:00

Im having some problems in the way a present an error mensage to my

  • 0

Im having some problems in the way a present an error mensage to my users. I “solved” the problem using two Goto instructions. Please take a look of the code:

<?php require_once("registration/include/membersite_config.php"); ?>
    <!DOCTYPE html>
    <html lang="en">
    <head><?php include_once("parts/head.php"); ?></head>
<body>
<div id="footerfix">
<?php include_once("parts/header.php"); ?>
    <div class="container">
        <div class="hero-unit">
<?php
if (isset($_GET['i'])) {
    unlink("users/thumbs/" . $_SESSION["user_code"] . ".jpg");
    header('Location: profile.php?i=mycv');
}
if (isset($_FILES['avatar']['tmp_name'])) {
    $file_ext = end(explode('.', $_FILES['avatar']['name']));
    if (in_array($file_ext, array('jpg', 'jpeg', 'png', 'gif')) == false) {
        echo("<h2>Error!</h2><p>Your profile photo have to be a picture file.</p>");
        goto nomore;
    }
    $src_size = getimagesize($_FILES['avatar']['tmp_name']);
    if ($src_size['mime'] == 'image/jpeg') {
        $src_img = imagecreatefromjpeg($_FILES['avatar']['tmp_name']);
    } elseif ($src_size['mime'] == 'image/png') {
        $src_img = imagecreatefrompng($_FILES['avatar']['tmp_name']);
    } elseif ($src_size['mime'] == 'image/gif') {
        $src_img = imagecreatefromgif($_FILES['avatar']['tmp_name']);
    } else {
        echo("<h2>Error!</h2><p>Incorrect file format.</p>");
        goto nomore;
    }
    $thumb_w = 150;
    if ($src_size[0] <= $thumb_w) {
        $thumb = $src_img;
    } else {
        $new_size[0] = $thumb_w;
        $new_size[1] = ($src_size[1] / $src_size[0]) * $thumb_w;
        $thumb = imagecreatetruecolor($new_size[0], $new_size[1]);
        imagecopyresampled($thumb, $src_img, 0, 0, 0, 0, $new_size[0], $new_size[1], $src_size[0], $src_size[1]);
    }
    imagejpeg($thumb, "users/thumbs/" . $_SESSION["user_code"] . ".jpg");
    //header('Location: profile.php?i=mycv');
    echo('<h2>Ready!</h2><p>Your profile picture is updated. <a href="profile.php">Go back</a>.</p>');
    nomore:
    echo "</div></div>";
    include_once("parts/footer.php");
    echo "</div></body></html>";
}
?>

I never understood why goto is the worst think that could happened to a code (at least, every one says that), i will like to hear your opinions about this, and if that is really the worst think ever, how still use my code whitout them? Thanks!

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:17:17+00:00Added an answer on May 25, 2026 at 7:17 pm

    The short answers why GOTO is a bad idea: readability suffers. Consider this:

    <?php require_once("registration/include/membersite_config.php"); ?>
    <!DOCTYPE html>
    <html lang="en">
    <head><?php include_once("parts/head.php"); ?></head>
      <body><div id="footerfix">
      <?php include_once("parts/header.php"); ?>
        <div class="container">
          <div class="hero-unit">
    <?php
    if(isset($_GET['i'])){ unlink("users/thumbs/".$_SESSION["user_code"].".jpg"); header('Location: profile.php?i=mycv');}
    if(isset($_FILES['avatar']['tmp_name'])){
        $file_ext = end(explode('.',$_FILES['avatar']['name']));
        if(in_array($file_ext,array('jpg','jpeg','png','gif'))==false){
            echo("<h2>Error!</h2><p>Your profile photo have to be a picture file.</p>");
        }
        else {
            $src_size=getimagesize($_FILES['avatar']['tmp_name']);
            if($src_size['mime']=='image/jpeg') {
                $src_img=imagecreatefromjpeg($_FILES['avatar']['tmp_name']);
            } elseif($src_size['mime']=='image/png') {
                $src_img=imagecreatefrompng($_FILES['avatar']['tmp_name']);
            } elseif($src_size['mime']=='image/gif') {
                $src_img=imagecreatefromgif($_FILES['avatar']['tmp_name']);
            } else {
                echo("<h2>Error!</h2><p>Incorrect file format.</p>");
            }
            if(!empty($src_img)) {
                $thumb_w = 150;
                if($src_size[0]<=$thumb_w){
                    $thumb=$src_img;
                }else{ 
                    $new_size[0] = $thumb_w;
                    $new_size[1] = ($src_size[1]/$src_size[0])*$thumb_w;
                    $thumb=imagecreatetruecolor($new_size[0],$new_size[1]);
                    imagecopyresampled($thumb,$src_img,0,0,0,0,$new_size[0],$new_size[1],$src_size[0],$src_size[1]);
                }
                imagejpeg($thumb,"users/thumbs/".$_SESSION["user_code"].".jpg");
                //header('Location: profile.php?i=mycv');
                echo('<h2>Ready!</h2><p>Your profile picture is updated. <a href="profile.php">Go back</a>.</p>');
            }
        }
    }
    ?>
        </div></div>
        <?php include_once("parts/footer.php"); ?>
    </div>
    </body>
    </html>
    

    Anyway, you should consider separating your template from logic (google “MVC”) and use at least functions for complex operations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some problems with a datagridview element I'm using in VS2008. This DataGridView
I'm having some problems displaying the contents of one NSArrayController in two windows defined
I've been having some problems with using BerkeleyDB. I have multiple instances of the
I'm trying to parse some XML using simpleXML in PHP. The problem I'm having
I have an audio app that is having some problems with the way iOS
Currently having some problems- now = datetime.datetime.now() month = now.strftime(%B) site = wikipedia.getSite('en', 'wikiquote')
Im having some problems getting the Sticky Footer to work on my site. If
I'm having some problems integrating MS MapPoint 2009 into my WinForms .Net 2.0 application
I have been having some problems trying to get my PHP running. When I
I'm having some problems with the ranking used by fulltext search in SQL Server.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.