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 7973795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:12:24+00:00 2026-06-04T08:12:24+00:00

I have a php script below where it adds a database row if a

  • 0

I have a php script below where it adds a database row if a new or existing file is uploaded:

<?php
session_start();
...//connect to DB

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

    mysql_query($imagesql);
} else {
    $imagesql = "INSERT INTO Image (ImageFile) 
    VALUES ('ImageFiles/".mysql_real_escape_string($_FILES['fileImage']['name'])."')";
    mysql_query($imagesql);
}
mysql_close();
?>

<script language="javascript" type="text/javascript">window.top.stopImageUpload(<?php echo $result ? 'true' : 'false'; ?>, '<?php echo $_FILES['fileImage']['name'] ?>');</script>

But the problem is that I want to add an if statement below the else statement when $result = 2 so that it deletes a database row. When I try this, then it doesn’t insert a database row after uploading a new or existing file.

if ($result = 2){
  $imagecancelsql = "DELETE FROM Image 
  WHERE ImageFile = 'ImageFiles/". mysql_real_escape_string($_FILES['fileImage']['name'])."'";
  mysql_query($imagecancelsql);
}

So my question is: how am I supposed to place the if statement above in the php script so that it performs its necessary database update?

  • 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-04T08:12:26+00:00Added an answer on June 4, 2026 at 8:12 am

    You don’t define anywhere your $result var, so the if would never get executed. Anyway you should place it there:

    <?php
    session_start();
    ...//connect to DB
    
    $result = 0;
    if( file_exists("ImageFiles/".$_FILES['fileImage']['name'])) {
        $imagesql = "INSERT INTO Image (ImageFile) 
        VALUES ('ImageFiles/".mysql_real_escape_string($_FILES['fileImage']['name'])."')";
    
        mysql_query($imagesql);
    } else {
        $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();
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP script to re size image file as below; $file =
I have a few questions regarding a PHP Pagination Script For Flat File Database
I have a small script which im using to test PHP mail(), as below:
I have a PHP script that executes a .bat file using system(cmd /c C:\dir\file.bat);
I have a PHP script where I create a new process using proc_open().It executes
I have a PHP script that inserts data into a mysql database. The table
I have written a PHP script below try to Post the JSON encoded string
I have a PHP script that processes file uploads. The script tries to organise
I have php script as below; $ages = array(Peter=>32, Quagmire=>30, Joe=>34); $ages2 = 'Peter=>32,
I have a php script which uses this below when a user uploads a

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.