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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:40:50+00:00 2026-06-17T10:40:50+00:00

I’m trying to make a form that will update a row in a database.

  • 0

I’m trying to make a form that will update a row in a database. So I can make titles for posts and stuff like that.

Can anyone help me?

  • 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-17T10:40:51+00:00Added an answer on June 17, 2026 at 10:40 am

    Update: Given the short string of code you have provided, I shall make some minor updates to my answer.

    Your question is very general, but I’ll provide some code to get you started. For instance if you want to update the title for post #60.

    HTML

    <form action='update.php' method='POST'>
        <label for='title'>Post title:</label>
        <input type='text' id='title' name='title' required>
    
        <label for='content'>Post body:</label>
        <textarea cols='80' rows='10' id='content' name='content'></textarea>
    
        <input type='hidden' name='postID' value='60'>
        <button type='submit'>Update</button>
    </form>
    

    I’m assuming each post has a unique ID called id. Again this is a very simple example. For the sake of this example I’ll also assume your database is MySQL. I will use PDO here but feel free to use mysqli, or the mysql driver if you really have to.

    PHP (update.php)

    <?php
    
        // Define your MySQL credentials here
        define('DB_NAME', 'your database name');
        define('DB_HOST', 'localhost'); // usually it's localhost
        define('DB_PORT', 3306) // usually it's 3306
        define('DB_USER' 'username');
        define('DB_PASSWORD', 'password');
    
        // Check if your HTTP POST parameters are set
        if(!isset($_POST['title']) || !isset($_POST['content']) || !isset($_POST['id'])) {
            die('Missing POST parameters');
        }
    
        // Create a new PDO instance
        $db = new PDO("mysql:dbname=" . DB_NAME . ";host=" . DB_HOST . ";port=" . DB_PORT, DB_USER, DB_PASSWORD);
    
        $sql = 'UPDATE `text` SET `title` = :title, `content` = :content WHERE `id` = :id;';
    
        // Create a new PDOStatement by preparing it
        $statement = $db->prepare($sql);
    
        // Bind the values to the prepared statement
        // By doing this you don't have to worry about escaping them
        $statement->bindValue(':title', $_POST['title'], PDO::PARAM_STR);
        $statement->bindValue(':content', $_POST['content'], PDO::PARAM_STR);
        $statement->bindValue(':id', $_POST['postID'], PDO::PARAM_INT);
    
        // Execute the prepared statement
        $statement->execute();
    
        // Since we're doing an update, it is a good idea to check if the query succeeded.
        // rowCount() should return 1 here
        if($statement->rowCount()) {
            echo 'Post title updated.';
        }
    ?>
    

    For more information you can consult the MySQL documentation for the UPDATE query (or the documentation for your RDBMS).

    Hopefully this will get you started!

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.