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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:23:21+00:00 2026-05-31T11:23:21+00:00

I am working on a project. What I need to do is basically enter

  • 0

I am working on a project. What I need to do is basically enter some info into a form, have that form save it into a database, display the data, and then be able to edit the data. So far, I am able to do everything except edit the data. I’ve tried using $_GET to get the ID of the particular “bug” I need to edit, and I am able to do that, and get all of the information but I am not sure how to edit that particular ID in my database. Here is my handler: http://pastebin.com/mR6QWpJ7 and my form:

<form action="week10handle.php" method="POST">
        <fieldset width="300px">
            <legend width="300px"><b>Add a bug report</b></legend>
                Product Name:<br/><input type="text" name="product_name"><br/>
                Product Version: <br/><input type="text" name="product_version"><br/>
                Hardware Type: <br/><input type="text" name="hardware"><br/>
                Operating System: <br/><input type="text" name="os"><br/>
                Frequency: <br/><input type="text" name="frequency"><br/>
                Proposed Solutions: <br/><textarea name="solutions"></textarea><br/>
                <input type="submit" value="Submit">
        </fieldset>
</form>

Here is where I obtain the get data in my edit form page so far, but as of right now, I am not sure how to edit a particular ID in the database.

    $getbug = htmlspecialchars($_GET["bugid"]);


    if (!empty($getbug)){
        $getbuginfo = mysql_query("SELECT * FROM `bugs` WHERE `id`= '$getbug'");
        if ($getbuginfo = mysql_fetch_assoc($getbuginfo)){
            $edit_product_name = $getbuginfo['product_name'];
            $edit_prod_version = $getbuginfo['product_version'];
            $edit_hardware = $getbuginfo['hardware_type'];
            $edit_os = $getbuginfo['os'];
            $edit_frequency = $getbuginfo['frequency'];
            $edit_solutions = $getbuginfo['solutions'];
            ?>
<form action="week10handle.php" method="POST">
        <fieldset width="300px">
            <legend width="300px"><b>Edit bug <?php echo $getbug;?></b></legend>
                Product Name:<br/><input type="edit" name="product_name" value="<?php echo $edit_product_name;?>"><br/>
                Product Version: <br/><input type="edit" name="product_version" value="<?php echo $edit_prod_version;?>"><br/>
                Hardware Type: <br/><input type="edit" name="hardware" value="<?php echo $edit_hardware;?>"><br/>
                Operating System: <br/><input type="edit" name="os"value="<?php echo $edit_os;?>"><br/>
                Frequency: <br/><input type="edit" name="frequency"value="<?php echo $edit_frequency;?>"><br/>
                Proposed Solutions: <br/><textarea name="solutions"><?php echo $edit_product_name;?></textarea><br/>
                <input type="submit" value="Submit">
        </fieldset>
</form>

EDIT: Here is my update php code, but it is still not working, when I submit my form, it refreshes the page, but it doesn’t update the database:

<?php
if (mysql_connect('localhost','root','') && mysql_select_db('bug_reports')){

    $errors = array();

    if (isset($_POST['product_name'], $_POST['product_version'],$_POST['hardware'],$_POST['os'],$_POST['frequency'], $_POST['solutions'])){
        $product_name = mysql_real_escape_string(htmlentities($_POST['product_name']));
        $product_version = mysql_real_escape_string(htmlentities($_POST['product_version']));
        $hardware = mysql_real_escape_string(htmlentities($_POST['hardware']));
        $os = mysql_real_escape_string(htmlentities($_POST['os']));
        $frequency = mysql_real_escape_string(htmlentities($_POST['frequency']));
        $solutions = mysql_real_escape_string(htmlentities($_POST['solutions']));
        $getbug = mysql_real_escape_string(htmlentities($_POST['bugid']));
        if (empty($product_name) || empty($product_version) || empty($hardware) || empty($os) || empty($frequency) || empty($solutions)){
            $errors[] = 'All fields are required.';
        }

        if (!is_numeric($product_version) || !is_numeric($frequency)){
            $errors[] = 'Product version and frequency must both be numbers';
        }

        if (empty($errors)){
            $update = "UPDATE `bugs` SET `product_name` = '$product_name', `product_version = '$product_version', `hardware_type = '$hardware', `os` = '$os', `frequency` = '$frequency', `solutions` = '$solutions' WHERE `id` = $getbug";
            if ($update = mysql_query($update)){
                header('Location: week10handle.php');
            } else{
                $errors[] = 'Something went wrong, please try again.';
            }
        } else{
            foreach($errors as $error){
                echo '<p><strong>'.$error.'</strong></p>';
            }
        }

    }else{
    $getbug = htmlspecialchars($_GET["bugid"]);
    }



    if (!empty($getbug)){
        $getbuginfo = mysql_query("SELECT * FROM `bugs` WHERE `id`= '$getbug'");
        if ($getbuginfo = mysql_fetch_assoc($getbuginfo)){
            $bugid = $getbuginfo['id'];
            $edit_product_name = $getbuginfo['product_name'];
            $edit_prod_version = $getbuginfo['product_version'];
            $edit_hardware = $getbuginfo['hardware_type'];
            $edit_os = $getbuginfo['os'];
            $edit_frequency = $getbuginfo['frequency'];
            $edit_solutions = $getbuginfo['solutions'];
            ?>
    <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
        <fieldset width="300px">
            <legend width="300px"><b>Edit bug <?php echo $getbug;?></b></legend>
                Product Name:<br/><input type="edit" name="product_name" value="<?php echo $edit_product_name;?>"><br/>
                Product Version: <br/><input type="edit" name="product_version" value="<?php echo $edit_prod_version;?>"><br/>
                Hardware Type: <br/><input type="edit" name="hardware" value="<?php echo $edit_hardware;?>"><br/>
                Operating System: <br/><input type="edit" name="os"value="<?php echo $edit_os;?>"><br/>
                Frequency: <br/><input type="edit" name="frequency"value="<?php echo $edit_frequency;?>"><br/>
                Proposed Solutions: <br/><textarea name="solutions"><?php echo $edit_product_name;?></textarea><br/>
                <input type="hidden" name="bugid" value="<?php echo $bugid;?>" >
                <input type="submit" value="Update">
        </fieldset>
    </form>
<?
        }else{
            echo "something went wrong";
        }
    }else{
        echo "No bug found.";
    }

}else
    echo 'Could not connect at this time.';

?>
  • 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-31T11:23:22+00:00Added an answer on May 31, 2026 at 11:23 am

    A typical way to detect an update, as opposed to an insert, would be to check for a value for id. So, in your edit form add a hidden field to pass the id to the handler and then in your handler you can decide whether to process it as insert or update based on the presence of the id field.

    if (isset($_GET['id']) {
    
        // do update
        $sql = 'UPDATE `bugs` SET ... WHERE id = ' . intval($_GET['id']);
    
    } else {
    
        // do insert
        $sql = 'INSERT INTO `bugs` VALUES ....';
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a small project and I need some help. I have
We're currently working on a python project that basically reads and writes M2M data
I'm working on a little project, basically I have some text on my PHP/HTML
I just wanted some input on a project that I'm working on. Basically, I'm
I am working on a project and I need to save user configuration. The
I am working on a project that requires classification of characters and symbols (basically
I have a project i'm working on where i need to verify the files
I'm currently working on a project that requires me to match our database of
I am working on a Scorm MVC project. Basically I need to update a
I'm currently working on a project that's based on Android. Without getting into many

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.