Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 未从Ajax发送到mysql数据库的值_Php_Jquery_Mysql_Ajax_.post - Fatal编程技术网

Php 未从Ajax发送到mysql数据库的值

Php 未从Ajax发送到mysql数据库的值,php,jquery,mysql,ajax,.post,Php,Jquery,Mysql,Ajax,.post,我试图让jquery的.ajax()将值发送到表单: <form method="post" id="FanDetail"> <label for="bio">Brief Bio<br /></label> <textarea id="bio" name="fan_bio" cols="27" row

我试图让jquery的.ajax()将值发送到表单:

                    <form method="post" id="FanDetail">
                        <label for="bio">Brief Bio<br /></label>
                            <textarea id="bio" name="fan_bio" cols="27" rows="3"></textarea><br />
                        <label for="dob">Date of Birth<br/></label>
                            <input id="dob" name="fan_dob" value="(e.g. 01/05/1965)" onFocus="clearText(this)" /><br />     
                        <label for="zip">Location<br /></label>
                            <div class="ui-widget">
                                <input id="zip" name="term" value="What is your Zipcode?" onFocus="clearText(this)" /><br />
                                <input id="actualZip" type="hidden" name="actualzipval" value="" />
                            </div><!--ui-widget :: zip -->
                        <label for="occup">Occupation<br /></label>
                            <div class="ui-widget">
                                <input id="occup" type="text"  name="term2" value="e.g. Computer Programmer, etc" onFocus="clearText(this)" /><br />
                                <input id="actualOccup" type="hidden" name="actualOccupval" value="" />
                            </div><!--ui-widget :: occup -->
                        <label for="fbkurl">Facebook Handle&nbsp;[?]<br /></label>
                            <input id="fbkurl" type="text"  name="fan_fbk" value="e.g. SportsFan12" onFocus="clearText(this)" /><br />
                        <label for="twiturl">Twitter Handle&nbsp;[?]<br /></label>
                            <input id="twiturl" type="text"  name="fan_twit" value="e.g. AboutSports2012" onFocus="clearText(this)" /><br />
                        <label for="phoNum">Phone Number<br /></label>
                            <input id="phoNum" type="text"  name="fan_pho" value="cell or home phone" onFocus="clearText(this)" /><br />
                    <input style="background-image:url('img/save.png');" type="submit" name="saveAbout" value="" id="submit" />
                    </form>
<div class="success" style="display:none;">Got it!</div>
这个JS文件,然后连接到一个php脚本,该脚本通过
PDO
将它们发送到
mysql
更新的PHP:

///////////////////////////////////////////////
######## Get  Input to Submit ############## //
///////////////////////////////////////////////
$fanBio = $_POST['bio'];             //////
$fanDob = $_POST['dob'];             //////
$zipval = $_POST['zip'];             //////
$occupval = $_POST['occup'];         //////
$facebookurl = $_POST['fbkurl'];         //////
$twitterurl = $_POST['twiturl'];         //////
$phoneNum = $_POST['phoNum'];        //////
$fanID = 1;
///////////////////////////////////////////////

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 = ?
    ");
    $sth->bindValue(1,$fanBio);
    $sth->bindValue(2,$fanDob);
    $sth->bindValue(3,$zipval);
    $sth->bindValue(4,$occupval);
    $sth->bindValue(5,$facebookurl);
    $sth->bindValue(6,$twitterurl);
    $sth->bindValue(7,$phoneNum);
    $sth->bindValue(8,$fanID);
    $sth->execute();
    $count = $stmt->rowCount(); // check row count
    $sth->debugDumpParams(); ## debugging query
} 
我收到的错误:。它说在我填写完所有的
输入后
s
明白了.success

我试过:

  • 通过mysql手动输入此信息-工作正常
  • 运行Javascript控制台进行调试,它在JS端发送的很好,因为我得到了这个,一旦我点击发送按钮:
当我填写输入并查看网络->响应下的JS控制台时,我在PHP文件上看到:

   SQL: [107] 
    UPDATE Fan 
    SET fanBio=?,fanDob=?,fanDetLocID=?,occupID=?,fanFbk=?,fanTwit=?,fanPho=?
    WHERE fanID = 1

Params:  7
Key: Position #0:
paramno=0
name=[0] ""
is_param=1
param_type=2
Key: Position #1:
paramno=1
name=[0] ""
is_param=1
param_type=2
Key: Position #2:
paramno=2
name=[0] ""
is_param=1
param_type=2
Key: Position #3:
paramno=3
name=[0] ""
is_param=1
param_type=2
Key: Position #4:
paramno=4
name=[0] ""
is_param=1
param_type=2
Key: Position #5:
paramno=5
name=[0] ""
is_param=1
param_type=2
Key: Position #6:
paramno=6
name=[0] ""
is_param=1
param_type=2

应该
$sth->execute()将所有绑定参数作为一个数组包含在其中???

尝试以下内容,我希望它能在这里发布更详细的教程哦,它是如何工作的


为什么不使用jqueryajax函数而不是post呢?您介意使用上面的代码显示一个示例吗?对不起,更改JS不起作用。请参阅上面更新的错误主题:为什么不序列化表单?它干净多了@Flukey在我更快地同意之前,它看起来像是他在做什么,但我正在尝试重新做它,因为直接查询字符串方式可能更直接,导致的错误更少。@CodeTalk我不确定,但似乎问题可能出在您的直接更新部件更新风扇集fanB中。。。。。。尝试使用他们在这里做的方式我从来没有使用过PDO,但它看起来像是更新部分中的文件中断。这里是一个关于如何使用PDO更新的教程
   SQL: [107] 
    UPDATE Fan 
    SET fanBio=?,fanDob=?,fanDetLocID=?,occupID=?,fanFbk=?,fanTwit=?,fanPho=?
    WHERE fanID = 1

Params:  7
Key: Position #0:
paramno=0
name=[0] ""
is_param=1
param_type=2
Key: Position #1:
paramno=1
name=[0] ""
is_param=1
param_type=2
Key: Position #2:
paramno=2
name=[0] ""
is_param=1
param_type=2
Key: Position #3:
paramno=3
name=[0] ""
is_param=1
param_type=2
Key: Position #4:
paramno=4
name=[0] ""
is_param=1
param_type=2
Key: Position #5:
paramno=5
name=[0] ""
is_param=1
param_type=2
Key: Position #6:
paramno=6
name=[0] ""
is_param=1
param_type=2
 $(document).ready(function(){
        $("form#FanDetail").submit(function() {
        // store the values from the form input box, then send via ajax below
        var bio = ;
        var dob = $('#dob').val();
        var zip = $('#actualZip').val();
        var occup = $('#actualOccup').val();
        var fbkurl = $('#fbkurl').val();
        var twiturl = $('#twiturl').val();
        var phoNum = $('#phoNum').val();
                  $.ajax({
                  type: "POST",
                  url: "../src/php/registration/about/submitvalues_about_tab.php"
                  data: "bio=" + bio + "&dob=" + dob +"&zip=" + zip + "&occup=" + occup      +"&fbkurl=" + fbkurl + "&twiturl=" + twiturl +"& phoNum=" +  phoNum,
                  }).done(function( msg ) {
                     $('div.success').fadeIn();
                 });
           return false;
        });
    });