-1

我有一个编辑个人资料,用于用户的个人资料。好吧,Javascript 似乎只获得了 Age's Form 的价值。PHP 文件正在老化,但没有其他文件,它没有更新数据库。

Javascript:

function UpdateProfile() {
var newage = $("#NewAge").val();
var newimage = $("#NewImage").val();    
var newbio = $("#NewBio").val();    
var dataString = 'newage=' + newage || 'newimage=' + newimage || 'newbio=' + newbio;    
if (newbio.length , newage.length , newimage.length == 0) {
    $('#Required').fadeIn(300);
    $('#Mask').fadeIn(300);     
} else {
    $.ajax({
        type: "POST",
        url: "update_profile.php",
        data: dataString,
        cache: false,
        success: function (UpdateProfile) {
            $('#EditInfo').hide();
            $("#UpdatedProfile").html(UpdateProfile);
            $("#UpdatedProfile").fadeIn('slow');
            $("#Age").html('Age: ' + newage);
            $('#Image').html('<img src="' + newimage +'" width="150" height="100" />');                                             
        }
    });
   }
}

这是 update_profile.php 文件:

<?php session_start() ?>
<?php include 'connect.php' ?>     
      <?php
        $newimage = $_POST['newimage'];
        $newbio = $_POST['newabout'];
        $newage = $_POST['newage'];         
            $update = "UPDATE members SET bio=(".$newbio.") age=(".$newage.") image=(".$newimage.") WHERE id='".$id."'";
            $res = mysql_query($update);
            echo 'Success: Profile Updated!<br />';
            echo $update . '<br />';
      ?>

HTML:

<input type="text" id="NewAge" value="<?php echo $age ?>" maxlength="2" />
<input type="text" id="NewImage" value="<?php echo $image ?>" maxlength="500" />
<textarea id="NewBio" style="width: 500; max-width: 500; height: 100; max-height: 150;"><?php echo $bio ?></textarea>
<input type="submit" value="Update Profile" onClick="UpdateProfile()" />

更新输出的代码是这样的:

Success: Profile Updated!
UPDATE members SET bio=() age=(18) image=() WHERE id='1'
4

2 回答 2

1

试试这个:

$.ajax({
    ...
    data: { newimage: newimage,
            newage: newage,
            newbio: newbio }
   ...
});
于 2013-05-18T19:53:14.303 回答
0

更新这一行:

 $newbio = $_POST['newabout'];

 $newbio = $_POST['newbio'];

它应该工作。

于 2013-05-18T19:21:11.293 回答