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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:14:43+00:00 2026-05-14T00:14:43+00:00

Looking for a good tutorial on how to update a mysql database using a

  • 0

Looking for a good tutorial on how to update a mysql database using a php 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-05-14T00:14:44+00:00Added an answer on May 14, 2026 at 12:14 am

    Updating data can be pretty simple. Let’s start with a form, for starters:

    <form method="post" action="submit.php">
      <input type="text" name="id" value="12" />
      <input type="text" name="value" value="Jonathan" />
      <input type="submit" />
    </form>
    

    This form will send the data over to our submit.php script where we can handle it, and pass it into our database. Since our form method is “post,” all of our values will be sent through the POST super array in PHP (this is not the case if you are using file uploaders). So within our submit.php page, we can print the ID and Value values like this:

    print $_POST["id"]; // the name of the HTML element is the key
    print $_POST["value"]; // again, note that we use the name as the key
    

    You’ll want to be careful about passing user-submitted values directly into your queries, so it’s nice to clean up the data using a function like mysql_real_escape_string():

    $id = mysql_real_escape_string( $_POST["id"] );
    $value = mysql_real_escape_string( $_POST["value"] );
    

    The next thing we’ll want to do is place these in a query:

    $sql = "UPDATE mytable SET value = '{$value}' WHERE id = {$id}";
    

    This is a good time not state that I don’t encourage you to use this example code in a live environment. You’ll want to look up sql-injections, and how to avoid them. The code I’m providing here is merely an example. After our values are entered, the query that will be ran actually looks like this:

    UPDATE mytable SET value = 'Jonathan' WHERE id = 12
    

    Now, in order to run this, we need to be connected to a database.

    $host = "localhost"; 
    $user = "root"; 
    $pass = "";
    $database = "myDatabase";
    $conn = mysql_connect($host, $user, $pass) or die( mysql_error() );
            mysql_select_db($database) or die( mysql_error() );
    

    All we’re doing here is storing our mysql-user-account credentials in arrays, and passing them into a connect-function. This code should be pretty self-explanatory, but let me know if it’s at all unclear.

    Once you’ve got that, you’re ready to run your query. Remember that we stored it in an array called $sql:

    $result = mysql_query( $sql ) or die( mysql_error() );
    

    That’s it. You did it! The data, assuming nothing went wrong, is now updated in your database. There are numerous ways you can increase the information provided back to the user via this script. Also worth noting is that you’ll want to sanitize your data before even allowing the script to run – if it’s not acceptable data (somebody trying to inject their own queries) you’ll want to spit it back.

    Check out the MySQL Functions in the PHP Documentation for more goodies, and be sure to return here when you have more specific questions!

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

Sidebar

Ask A Question

Stats

  • Questions 439k
  • Answers 439k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Two possibilities here (in my example I will be using… May 15, 2026 at 4:53 pm
  • Editorial Team
    Editorial Team added an answer Whether they're the same depends on context. position returns a… May 15, 2026 at 4:53 pm
  • Editorial Team
    Editorial Team added an answer The vector<MyPoint> is preferable, because MyPoint is likely: to be… May 15, 2026 at 4:53 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.