Reputation: 11
JS FILE
buttons: {
save : function() {
calEvent.id = id;
id++;
calEvent.start = new Date(startField.val());
calEvent.end = new Date(endField.val());
calEvent.title = titleField.val();
calEvent.body = bodyField.val();
//post to events.php
$.post("events.php?action=save&start="+calEvent.start.getTime()/1000+"&end="+calEvent.end.getTime()/1000+"&title="+calEvent.title+"&body="+calEvent.body);
$calendar.weekCalendar("removeUnsavedEvents");
$calendar.weekCalendar("updateEvent", calEvent);
$dialogContent.dialog("close");
},,
"delete" : function() {
calEvent.id = id;
id++;
//post to events.php
$.post( "events.php", { action: "del", id: calEvent.id });
$calendar.weekCalendar("removeEvent", calEvent.id);
$dialogContent.dialog("close");
} ,
cancel : function() {
$dialogContent.dialog("close");
}
}
}).show();
PHP FILE
if ($action == 'del')
{
$id = $_GET['id'];
$del = "DELETE FROM meeting_rooms_calendar WHERE id='$id'";
$result = mysql_query($del, $link);
print_r($id);
}
elseif($action == 'save')
{
$title = $_REQUEST['title'];
$body = $_REQUEST['body'];
$start_time = (int)$_REQUEST['start'];
$start_time = $start_time + 60*60;
$end_time = (int)$_REQUEST['end'];
$end_time = $end_time + 60*60;
$start = date('c',$start_time);
$end = date('c',$end_time);
$sql = "INSERT INTO meeting_rooms_calendar(title,body,start,end) VALUES ('$title','$body','$start','$end')";
$result = mysql_query($sql, $link);
}
Now if I click save, save will post the request variables to PHP and PHP to the database, when I click DELETE it doesn't send the requested ID to PHP so PHP can't delete it from database how can I make the JS file send the ID to PHP.
If I do it manually by
www.myweb.com/events.php?action=del&id=1
This will delete it from database, so that means PHP works. It's just the JS part, it don't delete it automatically from database.
Upvotes: 0
Views: 149
Reputation: 22711
You need use $_POST
instead of $id = $_GET['id']
; since you are using jquery $.post
method
$action = $_POST['action'];
Upvotes: 1
Reputation: 22817
You are issuing a $.post
via JS, but your rely on $_GET
on your PHP code. Stick to $_POST
.
Upvotes: 0