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

  • Home
  • SEARCH
  • 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 7949943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:06:57+00:00 2026-06-04T02:06:57+00:00

I have a situation with my php code. What I am currently doing is

  • 0

I have a situation with my php code. What I am currently doing is using the iframe to link the javascript message with the phe script. In the javascript function stopImageUpload, I have stated that if success = 2, then display the cancel message for the file upload.

So what I have tried but failed to do in the php script is to try and state that if the $result = 2 (In other words if success = 2 message appears in javascript), then delete the database row. How can this be done?

Below is the form code:

var $fileImage = $("<form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='return imageClickHandler(this);' class='imageuploadform' >" + 
  "Image File: <input name='fileImage' type='file' class='fileImage' /></label><br/><br/><label class='imagelbl'>" + 
  "<input type='submit' name='submitImageBtn' class='sbtnimage' value='Upload' /></label>" +     
  "</p><p class='imagef1_cancel' align='center'><label>" + 
  "<input type='button' name='imageCancel' class='imageCancel' value='Cancel' /></label>" +
  "<iframe class='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px;solid;#fff;'></iframe></form>");

Below is the startImageUpload() function where it starts an file upload and where the cancel button function is stored:

  function startImageUpload(imageuploadform, imagefilename){
    $('.imagef1_cancel').eq(window.lastUploadImageIndex).find(".imageCancel").on("click", function(event) {
      return stopImageUpload(2);
      });     
    return true;
  }

Below is the stopImageUpload() function where it displays the cancel message using success and result:

function stopImageUpload(success, imagefilename){
  var result = '';
  if (success == 2){
    result = '<span class="imagecemsg"> The file upload was canceled!</span><br/><br/>';
  } else {
    result = '<span class="imageemsg">There was an error during file upload!</span><br/><br/>';
  }         
  return true;   
}

Finally below is the imageupload.php script which is linked to the QandATable.php (The script which contains the code above) using iframe and this is where the database row is suppose to be inserted and deleted from:

    <?php
      session_start();
      ...//connected to DB
      $result = 0;

if( file_exists("ImageFiles/".$_FILES['fileImage']['name'])) {
    $result = 1;

    $imagesql = "INSERT INTO Image (ImageFile) 
    VALUES ('ImageFiles/".mysql_real_escape_string($_FILES['fileImage']['name'])."')";

    mysql_query($imagesql);

}
    else
      {

      $result = 1;

        $imagesql = "INSERT INTO Image (ImageFile) 
        VALUES ('ImageFiles/".mysql_real_escape_string($_FILES['fileImage']['name'])."')";

mysql_query($imagesql);

      }

      if ($result == 2) {
        $imagecancelsql = "DELETE FROM Image 
                           WHERE ImageFile = 'ImageFiles/".
                           mysql_real_escape_string($_FILES['fileImage']['name'])."'";
        mysql_query($imagecancelsql);
      }
      mysql_close();
    ?>
    <script language="javascript" type="text/javascript">window.top.stopImageUpload(<?php echo $result ? 'true' : 'false'; ?>, '<?php echo $_FILES['fileImage']['name'] ?>');</script>
  • 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-06-04T02:06:58+00:00Added an answer on June 4, 2026 at 2:06 am

    There are severe issues with your code that need to be addressed:

    1)

    This line:

    return stopImageUpload(2);
    

    Is calling the function:

    function stopImageUpload(success, imagefilename){...}
    

    But the stopImageUpload function needs two parameters, success and imagefilename


    2)

    This function returns true, but should return the contents of result.

    function stopImageUpload(success, imagefilename){
      ...
      return true;   
    }
    

    3)

    Here you set $result with the value 0, and compare it with the value 2 ?!?

    $result = 0;
    
    if ($result == 2) {
    

    4)

    This function accepts two parameters, but none of them is used inside ?!?

    function startImageUpload(imageuploadform, imagefilename){...}
    

    Also, it is returning

    return stopImageUpload(2);
    

    or

    return true;
    

    Are you controlling this situation!

    Note: Where do you use this function ?!?


    5)

    This verification likely fails because file_exists checks whether a file or directory exists. So, if the file does not exist, surely the directory does, and it will continue to execute.

    if( file_exists("ImageFiles/".$_FILES['fileImage']['name'])) {
    

    you should use is_file that tells you if the file is a regular file.


    6)

    You should not be using mysql_query anymore, please read PDO Tutorial for MySQL Developers

    mysql_query($imagesql)


    Please read this topics: to learn why are you failing to achieve your goal

    PHP Variables

    JavaScript Variables

    JavaScript Functions

    PHP File Upload e.g. 1 | PHP File Upload e.g. 2 | PHP File Upload e.g. 3


    I hope this may help you getting on the right track and fixing some issues with your present code.

    Best of Luck!

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

Sidebar

Related Questions

CODE HERE: http://jsfiddle.net/B7Y43/ Hello fello programmers, I have the following situation: My PHP-script generates
I have a situation with my php code. In a previous page the user
I have the following situation. I have a PHP script that imports a CSV
I'm using mysql/php/apache . I have the following situation: 2 tables where I need
Imagine I have the following situation: File1.php <?php include(Function.php); log(test); ?> Function.php <?php function
I have a situation like this. <php> <redirect the page > <exit> <javascript> <redirect
Introduction to the situation For an application I'm currently developing, I need to code
Say currently I have url like : http://mydomain.com/showpost.php?p=123 Now I want to make it
I currently have a working, simple language implemented in Java using ANTLR. What I
Say you have a file myfile.php which executes some PHP code. Could this file

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.