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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:17:12+00:00 2026-06-15T18:17:12+00:00

I want to update a MySQL database with an input form, essentially a settings

  • 0

I want to update a MySQL database with an input form, essentially a settings page where a user can update/change their information. With this code below, the echo at the bottom runs and I’m not getting any errors, but the database isn’t updated. I tested it both on my local machine and on a server and it didn’t work with either, although I’m not sure that would have anything to do with it. $_SESSION['yourName'] is already set when the user logs in, so it will equal the current value in the database. I know there are tons of sql injection hole in here, but this is just a proof-of-concept code, not ready to go live. I tried running the query in phpMyAdmin and it worked fine.

PHP

if(isset($_POST['name']) || isset($_POST['password']) || isset($_POST['location']) || isset($_POST['img'])) {
 //put this in an external file for a little extra security
 $username = "my_username";
 $password = "my_password";
 $database = "database_name";
 $con = mysql_connect('localhost',$username,$password);
 if (!$con) {
    die('Oh poop.... Could not connect: ' . mysql_error());
 }
 //print item from database
 mysql_select_db($database, $con);

 if(isset($_POST['name'])) {
    $query = 'UPDATE users SET username=' . $_POST['name'] . 'WHERE username=' . $_SESSION['yourName'];
    mysql_query($query);
    $_SESSION['yourName'] = $_POST['name'];
 }
 if(isset($_POST['password'])) {
    $query = 'UPDATE users SET password=' . $_POST['password'] . 'WHERE username=' . $_SESSION['yourName'];
    mysql_query($query);
 }
 if(isset($_POST['location'])) {
    $query = 'UPDATE users SET location=' . $_POST['location'] . 'WHERE username=' . $_SESSION['yourName'];
    mysql_query($query);
    $_SESSION['location'] = $_POST['location'];
 }
 if(isset($_POST['img'])) {
    $query = 'UPDATE users SET img=' . $_POST['img'] . 'WHERE username=' . $_SESSION['yourName'];
    mysql_query($query);
    $_SESSION['img'] = $_POST['img'];
 }
 echo '<script type="text/javascript">alert("changes saved")</script>';
}

HTML

<form method="post">
    new name: <input type="text" name="name" /><br />
    new password: <input type="text" name="password" /><br />
    new location: <input type="text" name="location" /><br />
    new img: <input type="text" name="img" /><br />
    <input type='submit' name='save' value='save' />
    <input type='submit' name='logout' value='logout' />
</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-15T18:17:13+00:00Added an answer on June 15, 2026 at 6:17 pm

    try to modify you php statement by using double quotes instead of single quotes.

    $query = "UPDATE users SET username='" . $_POST['name'] . "' WHERE username= '" . $_SESSION['yourName'] . "'";
    

    but the query above is vulnerable with SQL Injection, please read the article below,

    • How to prevent SQL injection in PHP?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to update 2 of my database's fields according to user input.My code
I want to accomplish this (mysql) query: UPDATE table SET field = field +
I want to update an erb.html page in rails with information from a webscraping
I want to update a text field in my mysql database but it doesn't
i want update textarea content onclock on a input button for example: <input type=button
I want to update the lastlogin column value .i wrote the code like this
I want to update a table with PHP and mySQL. I need to add
I have a simple html input textbox in a very simple form. the information
PHP uses the name from a form to update a record in a MySQL
I have a problem updating an MySQL Database. I want to be able to

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.