Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.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
Javascript 无法更新我的数据库_Javascript_Php_Jquery - Fatal编程技术网

Javascript 无法更新我的数据库

Javascript 无法更新我的数据库,javascript,php,jquery,Javascript,Php,Jquery,好的,我有一个动态下拉列表,以用户选择最终目的地结束 一旦选择了目的地,我会弹出多个文本区域,显示该目的地的可编辑信息,如标签、说明、酒店等 我无法将这些可编辑文本区域与用户编辑的新信息一起保存回数据库 我看了一些使用form=post方法的教程,但我就是不能让它工作 这里是我的javascript的一个例子,它从我的ajax.php文件中获取数组,并在我的html部分中用descbo //grabs from ajax.php and generates description for tha

好的,我有一个动态下拉列表,以用户选择最终目的地结束

一旦选择了目的地,我会弹出多个文本区域,显示该目的地的可编辑信息,如标签、说明、酒店等

我无法将这些可编辑文本区域与用户编辑的新信息一起保存回数据库

我看了一些使用form=post方法的教程,但我就是不能让它工作

这里是我的javascript的一个例子,它从我的ajax.php文件中获取数组,并在我的html部分中用descbo

//grabs from ajax.php and generates description for that specific destination
        jQuery(".wrap").on('change', '#destination', function() {
            var data = 'destinationid=' +jQuery('#destination :selected').val();
            jQuery.post("<?php echo plugins_url(); ?>/Destination_Drop_Down_Menu/ajax.php", data, function(data) {
                if(data.errorcode ==0){
                    jQuery('#descbo1').html(data.chtml);

                }else{
                    jQuery('#descbo1').html(data.chtml);

                }

            }, "json");

        });
下面是我的ajax.php文件的工作原理示例,它根据前面的示例生成数组,然后显示文本区域框

// Gets the description info from the last destination select drop down menu
$destination_id = isset($_POST['destinationid']) ? $_POST['destinationid'] : 0;
if ($destination_id <> 0) {
$errorcoded1 = 0;
$strmsg = "";
$sqlD1="SELECT * from destination WHERE IDDestination= ". $destination_id . " ORDER BY name;";
$resultD1=mysql_query($sqlD1);
$contD1=mysql_num_rows($resultD1);
if(mysql_num_rows($resultD1)){
$chtmlD1 = '<div name="description" id="description">';
while($row = mysql_fetch_array($resultD1)){
    $chtmlD1 .='<textarea name="Description" cols="130" rows="10">' .  $row['description'] . '</textarea>';
}
$chtmlD1 .= '</div>';

echo json_encode(array("errorcode"=>$errorcodeD1,"chtml"=>$chtmlD1));
} else {
    $errorcodeD1 = 1;
    $strmsg = '<font style="color:#F00;">No Description available</font>';
    echo json_encode(array("errorcode"=>$errorcodeD1,"chtml"=>$strmsg));
}
}
这是我的html部分,它的Form method=post。我的php函数应该保存信息,但它只是重新存储页面,而不保存任何内容

 <form action="" method="POST">
        <table cellpadding="5" cellspacing="2" border="0">
        <h1 align="center">General Information</h1>
        <tr>
        <td>description:</td>
        <td><div class="wrap" id="descbo1"></div></td>
            </tr>
             <tr>
                <td>page title:</td>
                <td><div class="wrap" id="descbo2"></div></td>
            </tr>
            <tr>
                <td>Meta Keywords:</td>
                <td><div class="wrap" id="descbo3"></div></td>
            </tr><tr>
            <td>Meta Description:</td>
            <td><div class="wrap" id="descbo4"></div></td>
            </tr>
             <tr>
                <td>

                    <input type="hidden" name="addedit" value="" />
                    <input type="submit" value="submit" name="submit"  style="background:#e5f9bb; cursor:pointer; cursor:hand;" />
                </td>
            </tr>
    </table>
    </form>
</body>
</html>
<?php
//see if the form has been completed
if (isset($_POST['submit'])){
    $ID = $_POST['IDDestination'];
    $description = $_POST['description'];
         if($ID&&$description){
        $exists = mysql_query("SELECT * FROM destination WHERE IDDestination='$ID'") or  die("the Query could not be done ");
        if(mysql_num_rows($exists) !=0 ){
            //update the description
            mysql_query("UPDATE destination SET description='$description' WHERE   IDDestination='$ID'") or die ("Update could not be applied.");
            echo "successful";
    }
    }
}

?>
我不知道我做错了什么。也是个初学者


任何帮助都将不胜感激。

我可能有一个愚蠢的问题,但您在php中使用$\u POST['IDDestination',在javascript中使用destinationid

这可能与此有关吗

您是否检查过是否在进行sql查询的php中输入了if


这个$description=$\u POST['description']也不应该吗;而是读$description=$_POST['description']

危险:您正在使用并且应该使用。你也很容易受到现代API的影响,因为它会让你的工作变得更轻松。首先,不要包含一堆与你遇到的问题无关的代码。除了表单POST本身,听起来一切都很好,所以为什么要把你的问题弄得一团糟,并可能阻止人们回答,因为他们不想查看所有这些代码。第二,告诉我们你做了什么来调试它。行为在哪里与您希望它做的不同?您是否已完成var_dump$_POST以确保POST值按预期进行?您是否在代码中跟踪了值的更改以查看从何处获得意外结果?您没有名为IDDestination的表单元素,因此在使用$ID时,您的查询将失败。