Javascript不更新数据库

时间:2013-05-18 19:17:23

标签: php javascript jquery

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

使用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'

2 个答案:

答案 0 :(得分:1)

请改为尝试:

$.ajax({
    ...
    data: { newimage: newimage,
            newage: newage,
            newbio: newbio }
   ...
});

答案 1 :(得分:0)

更新此行:

 $newbio = $_POST['newabout'];

 $newbio = $_POST['newbio'];

它应该有用。