problem with updating sql data

0

hi friends I have a problem and I would like to know what you say or what I have wrong or I do not know, happens that I have a form that has one field that is filled by a query query, and then when editing a box the field is not updated Here I leave the code to be told that it may be wrong or how the solution would be. Thanks!

$(document).ready(function(){

$('input').blur(function(){
    var field = $(this);
    var parent = field.parent().attr('id');
    field.css('background-color','#F3F3F3');

    if($('#'+parent).find(".ok").length){
        $('#'+parent+' .ok').remove();
        $('#'+parent+' .loader').remove();
        $('#'+parent).append('<div><img src="img/loader.gif"/></div>').fadeIn('slow');
    }else{
        $('#'+parent).append('<div><img src="img/loader.gif"/></div>').fadeIn('slow');
    }

    var dataString='value='+$(this).val()+'&field='+$(this).attr('name');
    $.ajax({
        type: "POST",
        url: "peticion/editar-perfil.php",
        data: dataString,
        success: function(data) {
            field.val(data);
            $('#'+parent+' .loader').fadeOut(function(){
                $('#'+parent).append('<div><img src="img/check.png"/></div>').fadeIn('slow');
            });

        }
    });
});

}); // edit profile the form is:

       <form>
                                  <div class="form-group">
                                        <div id="content_name">Nombre<br/>
                                        <input type="text" id="name" class="form-control req" name="first_name" value="<?=$row['first_name']?>"/>
                                    </div>
                                </div>
                                    <div class="form-group">
                                       Apellidos<br/>
                                       <input type="text" id="lastname" class="form-control req" name="lastname" value="<?=$row['last_name']?>" />
                                        </div>
                                    <div class="form-group">
                                        Email<br/>
                                        <input type="text" id="email" class="form-control" name="email" value="<?=$row['email']?>" />
                                     </div>
                                    <div class="form-group">
                                        Biografía<br/>
                                        <textarea rows="7" cols="30" class="form-control"  name="biography"><?=$row['biography']?></textarea>
                                        </div>
                        </form>

BD connection:

<?php
sleep(1);
$data = $_POST['value'];
$field = $_POST['field'];

$host = '127.0.01';
$user = 'root';
$pass = '';
$db = 'n260m_20xxxxx21_wifi';
$mysqli = new mysqli($host,$user,$pass,$db) or die($mysqli->error);


$update="UPDATE users SET $field=$data WHERE id=1";
$mysqli->query($update);

echo $data;
// echo $update;
?>
    
asked by Jaime Mateus 21.08.2017 в 04:26
source

1 answer

2

I see an error in the update of your database:

Capture your data:

$first_name = $_POST['first_name'];
$lastname   = $_POST['lastname'];
$email      = $_POST['email'];
$biography  = $_POST['biography'];
$id         = 1;

In the update of the fields would be:

$update = "UPDATE users SET first_name='$first_name', lastname='$lastname', email='$email', biography='$biography' WHERE id='$id'";

If you look after the SET is done this way:

name='$valor'

If you had a value it would be something like this:

$update="UPDATE users SET field='$data' WHERE id='$id'";
    
answered by 21.08.2017 / 17:22
source