I am trying to build a site where you can modify and update a mysql database directly using contenteditable in combination with jquery, ajax and PHP. The code captures data via $_POST['content'] with some jquery/ajax to load a php file (save.php). The save.php file runs a mysql UPDATE to update the database using the $_POST['content'] information entered by contenteditable provided by the user.

我正在尝试构建一个站点,您可以使用contenteditable与jquery,ajax和PHP直接修改和更新mysql数据库。代码通过$ _POST ['content']使用一些jquery / ajax来捕获数据以加载php文件(save.php)。 save.php文件运行mysql UPDATE以使用用户提供的contenteditable输入的$ _POST ['content']信息更新数据库。

In the save.php file I use a unique ID to identify which row must be updated. This ID is accessible via URL. I try to capture the ID by $_GET['id'] and convert this to $var_id=$_GET['id']. My problem is that when I try to access the id ($var_id) variable obtained from the URL

在save.php文件中,我使用唯一ID来标识必须更新哪一行。此ID可通过URL访问。我尝试通过$ _GET ['id']捕获ID并将其转换为$ var_id = $ _ GET ['id']。我的问题是,当我尝试访问从URL获取的id($ var_id)变量时

ex. http://www.website.org/selectedvariant.php?id=100

the $var_id is not recognized in the save.php file and the mysql UPDATE does not work. I know that this a problem with accessing the $var_id variable because when I manually put the variable_id='100' it works properly. Indicating that the save.php file is just not getting a proper value for the $var_id variable.

save.php文件中无法识别$ var_id,并且mysql UPDATE不起作用。我知道这是访问$ var_id变量的一个问题,因为当我手动设置variable_id ='100'时它可以正常工作。指示save.php文件没有为$ var_id变量获取正确的值。

Any help to resolve this long-standing challenge would be greatly appreciated!

任何帮助解决这一长期挑战的人都将不胜感激!

save.php

<?php mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$content=mysql_real_escape_string ($_POST['content']); //gets the posted content
$var_id=$_GET['id'];

$sql="update table_list set column='$content' where id='$var_id'";
if (mysql_query($sql))
{echo 1;
}
?>

other.php file (only relevant (i think?)) info

other.php文件(只相关(我认为?))信息

 $(document).ready(function() {

    $("#save").click(function (e) {         
        var content = $('#editable').html();    

        $.ajax({
            url: 'save.php',
            type: 'POST',
            data: {
            content: content
            },

Most of this code has been pulled from the tutorial:

大部分代码都是从教程中提取的:

http://gazpo.com/2011/09/contenteditable/

Thanks, Ron

2 个解决方案

#1


2

When you make the ajax call, you need to pass both content and id via some method (get or post). In your code, you are sending content data via POST method to save.php. ID is not being sent to your php script anyhow. Change your url params to -

当你进行ajax调用时,你需要通过某种方法(获取或发布)传递内容和id。在您的代码中,您通过POST方法将内容数据发送到save.php。无论如何,ID不会被发送到您的PHP脚本。将您的网址参数更改为 -

url:'save.php?id='+WhatYouHaveInHand

更多相关文章

  1. Thinkphp中怎么接收GET变量?
  2. 无法使用dropzone上传多个文件
  3. 关注:PHP文件目录和文件本身的操作
  4. php exec文件从终端运行,而不是从浏览器运行
  5. log4php将不同级别的日志打印到不同的日志文件中
  6. PHP - 在外部服务器上读取文件?
  7. PHP变量类型+整型类型细节
  8. 仅在LARAVEL或AJAX中提交表单时,无需用户身份验证即可将文件上载
  9. PHP ZipArchive 实现压缩解压Zip文件

随机推荐

  1. sql plus如何新建新用户
  2. mysql 配置 explicit_defaults_for_times
  3. 怎么用SQL语句实现表中的一个字段加1啊??
  4. mysql表名忽略大小写
  5. ySQL 4.*或5.0.*的升级指南
  6. 如果至少有一条记录的值为1,则返回“是”
  7. 如何将这两个查询组合成1?
  8. 如何在一个查询中组合六个独立查询。表是
  9. mysql主从简单配置
  10. 从SQL字符串分割多桩分隔符