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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:56:53+00:00 2026-06-11T02:56:53+00:00

I want to update 2 of my database’s fields according to user input.My code

  • 0

I want to update 2 of my database’s fields according to user input.My code is something like this:

 <body>
<?php
 $db_server["host"] = "localhost"; //database server
$db_server["username"] = "root"; // DB username
$db_server["password"] = "mypass"; // DB password
$db_server["database"] = "mudb";// database name

$dbc = mysql_connect($db_server["host"], $db_server["username"], $db_server["password"]);
mysql_select_db($db_server["database"], $dbc);
$user =  $_COOKIE['mycookie'];

    $q = "SELECT * FROM members WHERE username='$user'"; 
    $r = mysql_query( $q,$dbc);
    while ($row = mysql_fetch_array($r, MYSQLI_ASSOC)) { 
    echo 'username: '.$row['username'], '<br/>';

    $password=$row['password'];
?>

<form method="post" id="changepasswordform" > 
<input type="password" id="newpassword" name="newpassword"/>
<input type="submit"  name="changepasswordbutton"  >  
       </form>

<?php

        echo 'email:        '.$row['email'], '<br/>'; 
        }
?>

<form method="post" id="changeemailform" >  

        <input type="text" id="newemail" name="newemail"/>

       <input type="submit" value="αλλαγή"  name="changeemailbutton"  >
       </form>

<?php
}


    if (isset($_POST['changepasswordbutton'])){

                       $newpassword=$_POST['newpassword'];
                $q2 = "UPDATE members SET password=$newpassword WHERE username='$user'"; 

                $r2 = mysql_query($q2,$dbc);

}   

if (isset($_POST['changeemailbutton'])){
                    $newemail=$_POST['newemail'];
                    $q3 = "UPDATE members SET email=$newemail WHERE username='$user'"; 
                $r3 = @mysql_query( $q3,$dbc);  
}
?>
</body>

However although my connection to my db is ok(SELECT displays results as expected) when i try to UPDATE , the values inside my db remain the same.I checked the values of $newpassword and $newemail and they do contain the user inputs each time.What am i missing here?

  • 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-11T02:56:55+00:00Added an answer on June 11, 2026 at 2:56 am

    You’re missing the '' (quotes) that supposed to surround the password field.
    change:

    UPDATE members SET password=$newpassword WHERE username='$user'
    

    to:

    UPDATE members SET password='{mysql_real_escape_string($password)}' 
    WHERE username='{mysql_real_escape_string($user)}'
    

    IMPORTANT:
    And even though it’s not related, please don’t use mysql_* functions – it’s deprecated and vulnerable to sql-injection. Better use PDO or MySQLi.

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

Sidebar

Related Questions

I want to update database when user leave the site. I am using php
I want to update a database field when a user presses the Facebook Like
So, I want to insert this query into the database file: UPDATE contas SET
I want to update a database in my asp.net application. The updated fields are
I have function to detect idle state of user. I want to update database
Basically i want to update my database with values from an array that i
i want to update my sqlite database but i cannot find the way to
i want to update all records in my database(mongodb),I tried to use command below
I want to always update the value of an update row in the database.
I want to do an update statement in my database, after an element gets

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.