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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:20:37+00:00 2026-06-04T19:20:37+00:00

I am trying to update a record in a database. The code is meant

  • 0

I am trying to update a record in a database. The code is meant to allow users to update an entry on a website with the option to edit the image as well. When I was initially testing this code it worked with no issues. When they selected an image it would update the image, and when they did not select an image it would not include the image in the updating. When I moved this code to the page that it needs to be on it is no longer working. It is always reading it as if the user has not selected an image to upload. The only thing that has changed between the test code and this code is the names in the database, and the addition of mysql_real_escape_string() for the variables $title and $description.

Here is the PHP code that is not working for me:

<?php
require_once ("connect.php");
if (isset($_POST['description'])) {
    $id = $_GET['id'];
    $title = $_POST['title'];
    $description = $_POST['description'];
    $title = mysql_real_escape_string($title);
    $description = mysql_real_escape_string($description);
    $target = "../images/contests/";
    $target = $target.basename( $_FILES['image']['name']);
    $ok=1;

    if($_FILES['image']['name'] == "") {
        $query = "UPDATE tbl_contests SET contests_title='$title', contests_description='$description' WHERE contests_id='$id'";
        $result = mysql_query ($query);
            if ($result) {
            header ("Location: contests.php?=noimage");
            exit ();
        } else {
            header ("Location: contests.php?=error");
            exit ();
        }
    } else {
        if ($ok==0){
            header("Location: contests.php?=error");
        } else {
            if(move_uploaded_file($_FILES['image']['tmp_name'], $target)){
                echo "<p>Your upload was sucessful.</p>";
                $query = "UPDATE tbl_contests SET contests_title='$title', contests_description='$description', contests_image='$target' WHERE contests_id='$id'";
                $result = mysql_query ($query);
                if ($result) {
                    header ("Location: contests.php?=image");
                    exit ();
                } else {
                    header ("Location: contests.php?=error");
                    exit ();
                }
            }
        }
    } 
}
?>

Here is the form pertaining to the above code:

<?php
    $postnum = $_GET['id'];
    $query = "SELECT * FROM tbl_contests WHERE contests_id=".$postnum;
    $result= mysql_query($query);
    $row = mysql_fetch_array($result);
    $path = "../images/contests/";
    ?>

    <form action="update-past.php?id=<?php print $row[contests_id]; ?>" method="post" id="updatepast">
    <br /><label>Title:</label> <p><input type="text" name="title" id="title" class="input" value="<?php print $row[contests_title]; ?>" /></p>
    <?php if ($row['contests_image'] == !null) { ?>
    <p><img src="<?php print $path.$row['contests_image']; ?>" width="425" height="500" /></p>
    <br /><label>Edit Image: (Optional)</label> <p><input name="image" type="file" id="image" class="file" size="50" /></p>
    <?php } else { ?>
    <br /><br /><br /><br /><label>Add Image: (Optional)</label> <p><input name="image" type="file" id="image" class="file" size="50" /></p>
    <?php } ?>
    <br /><br /><br /><br /><br /><label>Description:</label><p><textarea name="description" cols="85" id="description" class="contentinput" rows="10"><?php print $row[contests_description]; ?></textarea></p>
    <p><input type="submit" name="submit" id="button" value="Edit" /></p>
    </form>
  • 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-04T19:20:38+00:00Added an answer on June 4, 2026 at 7:20 pm

    Try adding this to the form: enctype="multipart/form-data"

    Here’s some reading on form content types: http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.2

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

Sidebar

Related Questions

I am trying to update an existing record in a database using CoreData, but
I am trying to update records with a image button. here is my code:
i am trying to edit a mysql database record , there is seem to
I was trying to update a record in the database using Object.update_attributes(:field => parameter)
I'm trying to update a record from an Ms-Access table with VB.NET and ASP.NET.
I'm trying to update a single record in a table, but when I run
Im trying to update the contents of an element after running some php code.
Scenario: I'm just trying to update my database with the changes made by the
I am trying to update mysql data by letting users submit a form. The
I'm trying to update my database records, but no changes are made and no

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.