0

I am working with a MLM company where com has to register the member, if it detects any mistake in data, it has to update the data of member again.

I have the right code which works well when all fields has to update but problem is it does not work for individual input boxes. Please give me solution of this problem.

<?php
if(isset($_POST['update'])) {
    $dbhost = 'localhost';
    $dbuser = 'vvvv';
    $dbpass = 'xxxx';
    $conn = mysql_connect($dbhost, $dbuser, $dbpass);
    if(! $conn ) {
        die('Could not connect: ' . mysql_error());
    }
    $usrid = $_POST['uid'];
    $pwrd = $_POST['pwd'];
    $nm = $_POST['noe'];
    $fnm = $_POST['fn'];
    $addrs = $_POST['adrs'];
    $cntn = $_POST['cnt_no'];
    $cty = $_POST['ct'];
    $sql = "UPDATE office_user ".
        "SET
            password = '$pwrd',
            name='$nm',
            father_name='$fnm',
            address='$addrs',
            contact_no='$cntn',
            city='$cty' ".
        "WHERE user_id = '$usrid'" ;

    mysql_select_db('my_db');
    $retval = mysql_query( $sql, $conn );
    if(! $retval ) {
        die('Could not update data: ' . mysql_error());
    }
    echo "Updated data successfully\n";
    mysql_close($conn);
}
?>
halfer
  • 19,824
  • 17
  • 99
  • 186
  • Why don't you populate the form with values from database first then when form saved, it will update the database – AdRock Mar 21 '14 at 15:52
  • 1
    Also you should wrap your POST variables in `mysql_real_escape_string($_POST['uid'])` etc – AdRock Mar 21 '14 at 15:54
  • Please click [here](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?rq=1) to learn more about SQL injection. – 9997 Mar 21 '14 at 15:59
  • 2
    The usual technique is to validate all the input fields before doing the update, not updating the incorrectly completed fields on a second pass – andrew Mar 21 '14 at 16:08

0 Answers0