简体   繁体   中英

I would like to have my edit function to work when i click on the edit image

I would like to have my edit function to work when i click on the edit image. I have a function to edit an event but it wont work when i click on the image. The delete code works when i click on the event: delete function/edit function:

  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><a><img src="../../images/delete.png" title="delete" width="14" id="delbut'+event.id+'" border="0" style="padding-right:5px; padding-top:2px;" /></a></div>';
                $(this).append(layer);
                $("#delbut"+event.id).hide();
                $("#delbut"+event.id).fadeIn(300);
                $("#delbut"+event.id).click(function() {
                $.ajax({
                url: '<?=base_url();?>testcalendar/fullcalendar/delete_events.php',
                data: 'id=' + event.id ,
                type: "POST",
                });
                var nTime = 1 * 50;
                window.setTimeout("location.reload()", nTime);
                });
                $("#edbut"+event.id).hide();
                $("#edbut"+event.id).fadeIn(300);
                $("#edbut"+event.id).click(function() {
                    var title = prompt('Current Event Title: ' + event.title + '\n\nNew Event Title: ');

                    if(title){
                $.ajax({
                url: '<?=base_url();?>testcalendar/fullcalendar/update_title.php',
                data: 'title='+ event.title+'&id='+ event.id ,
                type: "POST",
                });
                    }
                });
            },

delete_events.php:

<?php
$id = $_POST['id'];
 try {
 $bdd = new PDO('mysql:host=localhost;dbname=develop-calendar', 'root', 'root');
 } catch(Exception $e) {
  exit('Unable to connect to database.');
 }
$sql = "DELETE from evenement WHERE id=".$id;
$q = $bdd->prepare($sql);
$q->execute(array($id));
?>

update_title.php:

    <?php
$id = $_POST['id'];
$title = $_POST['title'];
// connection to the database
try {
$bdd = new PDO('mysql:host=localhost;dbname=blackboks-calendar', 'calendar-boks', '19xantia');
 } 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();
?>

When i click on the edit icon there is an prompt to edit the title but when i type in a new title and click on ok it wont update. i think that there is something wrong with my update_title.php file but i dont know for sure.

There is a problem here

 $sql = "UPDATE evenement SET title=".$title "WHERE id=".$id;

Needs to be

 $sql = "UPDATE evenement SET title=" . mysql_real_escape_string($title) . " WHERE id=" . mysql_real_escape_string($id);

Indeed, the space before WHERE I edited already on previous answer.

You can also always try to debug what is returning by the script if you look into the Network tab inside Developer Console (F12 in most browsers).

Or check the results of the ajax call.

$.ajax({
  url: '<?=base_url();?>testcalendar/fullcalendar/delete_events.php',
  data: 'id=' + event.id ,
  type: "POST",
}).done(function(data) {
  alert(data); // Only for testing
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM