无法让我的数据库更新

时间:2014-04-21 19:45:36

标签: javascript php jquery

好的,所以我有动态下拉菜单,用户选择最终目的地。

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

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

我使用form = post方法观看了一些教程但我无法让它工作。

这是我的javascript的一个示例,它从我的ajax.php文件中抓取数组并使用#descbo在我的html部分中显示...

//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方法= 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";
    }
    }
}

?>

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

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:-1)

我可能有一个愚蠢的问题,但你在php中使用$_POST['IDDestination'],在javascript中使用destinationid

可能与此有关吗?

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

也不应该$description = $_POST['description'];而是阅读$description = $_POST['Description'];

相关问题