dongpan1871 2012-03-28 17:03
浏览 41
已采纳

不会更新数据库中的记录

My problem right now: No values are getting updated on a specific ID as specified (hardcoded) in the WHERE clause.

Anyone see what I'm doing wrong?

I have a form with about 7 fields to fill out. Currently, I am just trying to get the code to work with a hardcoded SQL query like WHERE fanID=2 then I will get it to work later with session variables.

I have (3) files:

HTML:

<form method="post" id="FanDetail">
  <textarea id="bio" name="fan_bio" />
  <input id="dob" name="fan_dob" />
  <input id="actualZip" />
  <input id="actualOccup" />
  <input id="fbkurl" />
  <input id="twiturl" />
  <input id="phoNum" />
</form>

a JS file, linked to in the HTML file:

$(document).ready(function(){
    $("form#FanDetail").submit(function() {
    // store the values from the form input box, then send via ajax below
    var bio = $('#bio').attr('value');
    var dob = $('#dob').attr('value');
    var zip = $('#actualZip').attr('value');
    var occup = $('#actualOccup').attr('value');
    var fbkurl = $('#fbkurl').attr('value');
    var twiturl = $('#twiturl').attr('value');
    var phoNum = $('#phoNum').attr('value');
    $.ajax({
        type: "POST",
        url: "../../../php/registration/about/submitvalues_about_tab.php",
        data: "bio="+ bio +"&amp; dob="+ dob +"&amp; zip="+ zip +"&amp; occup="+ occup +"&amp; fbkurl="+ fbkurl +"&amp; twiturl="+ twiturl +"&amp; phoNum="+ phoNum,
        success: function(){
            $('form#FanDetail').hide(function(){$('div.success').fadeIn();});
            }
        });
    return false;
    });
});

A PHP file, that is linked to by the above JS File:

///////////////////////////////////////////////
######## Get  Input to Submit ############## //
///////////////////////////////////////////////
$fanBio =       $_POST['fan_bio'];       //////
$fanDob =       $_POST['fan_dob'];       //////
$zipval =       $_POST['actualzipval'];  //////
$occupval =     $_POST['actualOccupval'];//////
$facebookurl =  $_POST['fan_fbk'];       //////
$twitterurl =   $_POST['fan_twit'];      //////
$phoneNum =     $_POST['fan_pho'];       //////
///////////////////////////////////////////////

try{
    ## Get current user and their session ID:
    $sessionvar = session_id();
    ### DB Connection already established above.
    $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );  

    // INSERT CLEAN DATA INTO TABLE…
    $sth = $dbh->prepare("
    UPDATE Fan 
    SET fanBio=?,fanDob=?,fanDetLocID=?,occupID=?,fanFbk=?,fanTwit=?,fanPho=?
    WHERE fanID=2
    ");
    $sth->bindParam(1,$fanBio);
    $sth->bindParam(2,$fanDob);
    $sth->bindParam(3,$zipval);
    $sth->bindParam(4,$occupval);
    $sth->bindParam(5,$facebookurl);
    $sth->bindParam(6,$twitterurl);
    $sth->bindParam(7,$phoneNum);
    $sth->execute();
} 

catch(PDOException $e){
file_put_contents('../../../../PDODBConnectionErrors.txt','ERROR: [submitvalues_about_tab.php] about '.$e->getMessage(), FILE_APPEND);  
}

I'm quite new to jQuery .ajax(), so go easy on me.

However, I'ved trouble shooting:

  • Check error log in the catch{} above - was initialially getting errors with my query, but I had fixed them and NOTHING appears in it anymore.
  • Tested query itself by hardcoding values - inputs fine.
  • Checked to make sure jquery file/php file are linked properly -> they are.

Thanks

  • 写回答

1条回答 默认 最新

  • doufei2194 2012-03-28 17:45
    关注

    One suggestion - .post() and serialize() to minimize your code a little:

    $(document).ready(function(){
        $("form#FanDetail").submit(function() {       
            $.post(
                "../../../php/registration/about/submitvalues_about_tab.php",
                $("form#FanDetail").serialize(),
                function(){
                    $('form#FanDetail').hide(function(){
                        $('div.success').fadeIn();
                });
              });
           return false;
        });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?