【问题标题】:JavaScript/PHP: Get input from prompt and update the databaseJavaScript/PHP:从提示中获取输入并更新数据库
【发布时间】:2014-02-26 13:18:53
【问题描述】:

所选事件的标题需要更改为提示输入的任何内容。

但它没有按预期工作。请建议/建议

JavaScript 函数:

eventMouseover: function(event, domEvent) {
                var layer = '<div id="events-layer" class="fc-transparent" style="position:absolute; width:100%; height:100%; top:-1px; text-align:right; z-index:100"><a><img src="../../images/editbt.png" title="edit" width="14" id="edbut'+event.id+'" border="0" style="padding-right:3px; padding-top:2px;" /></a></div>';

                $("#edbut"+event.id).hide();
                $("#edbut"+event.id).fadeIn(300);
                $("#edbut"+event.id).click(function() {
                var title = prompt( '\n\nNew Event Title: ');
                if(title){
                $.ajax({
                url: '<?=base_url();?>testcalendar/fullcalendar/update_title.php',
                data: 'title='+ event.title+'&id='+ event.id ,
                type: "POST",
                });
                    }
                });
            }, 

PHP 表单(update_title.php):

<?php
$id = $_POST['id'];
$title = $_POST['title'];
// connection to the database
try {
$bdd = new PDO('mysql:host=localhost;dbname=blackboks-calendar', 'root', 'root');
 } catch(Exception $e) {
exit('Unable to connect to database.');
}
 // update the records
$sql = "UPDATE evenement SET title=". $title ."WHERE id=".$id;
$q = $bdd->prepare($sql);
$q->execute();
?>

【问题讨论】:

  • 你在哪里发送ID? - 目前您只有标题,所以您的 WHERE 语句将为 null / nothing
  • 你的 JS 函数在 PHP 文件中吗?并尝试"UPDATE evenement SET title='". $title ."' WHERE id=".$id;
  • 标签之间是的
  • 试试你的 SQL 查询?我想你可能在那里。

标签: javascript php post fullcalendar prompt


【解决方案1】:

问题在于您发送标题时。它应该是标题而不是 event.title

改变

   data: 'title='+ event.title+'&id='+ event.id ,

    data: 'title='+ title+'&id='+ event.id ,

【讨论】:

  • 打开控制台,在浏览器中查看请求、参数和响应。
  • 那没有解决。但它有所帮助:) 我找到了答案,它只是 update_title.php 文件中的一个“”。
猜你喜欢
  • 1970-01-01
  • 2014-10-19
  • 1970-01-01
  • 1970-01-01
  • 2017-09-16
  • 2022-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多