acctman Posted March 10, 2009 Share Posted March 10, 2009 Hi without having to make a separate php file how i code and onclick to process a piece of php coding. The main file loading is a php file that echo's out html coding. So i just want to display a delete comment link and when a user clicks it will process the section of php code within the file. //delete comments if ($en['act'] == 'delcom') { mysql_query("DELETE FROM rate_picture_comments WHERE com_id=$row[com_id] AND com_for=$_SESSION[userid]"); header('Location: /edit-delcomments.html'); } Link to comment https://forums.phpfreaks.com/topic/148817-solved-process-php-code-on-link-click/ Share on other sites More sharing options...
Technocracy Posted March 10, 2009 Share Posted March 10, 2009 AJAX. Link to comment https://forums.phpfreaks.com/topic/148817-solved-process-php-code-on-link-click/#findComment-781476 Share on other sites More sharing options...
The Little Guy Posted March 10, 2009 Share Posted March 10, 2009 Hopefully this will get yoiu started: Place this in your javascript file: function ajaxPost(){ var contentType = "application/x-www-form-urlencoded; charset=UTF-8"; var ajaxRequest; try{ ajaxRequest = new XMLHttpRequest(); } catch (e){ try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ alert("Your Browser Doesn't support AJAX."); return false; } } } return Array(ajaxRequest,contentType); } function myAjax(commentID){ connect = ajaxPost(); connect[0].onreadystatechange = function(){ if(connect[0].readyState == 4){ // Modify "displaySomething" to your html's id name. document.getElementById('displaySomething').innerHTML = connect[0].responseText; } } // These are our post values add more if you want seperated by an ampersand (&): var va = 'act=delcom&com_id='+commentID; // This is our file that this function will act upon: connect[0].open("POST", 'grabPhp.php', true); connect[0].setRequestHeader("Content-Type", connect[1]); connect[0].send(va); } Place this in your HTML file: <a href="javascript:myAjax(1);">Click me... for something cool!</a> <div id="displaySomething"></div> Place this in its own PHP file: //delete comments if ($_POST['act'] == 'delcom') { mysql_query("DELETE FROM rate_picture_comments WHERE com_id={$_POST['com_id']} AND com_for={$_SESSION['userid']}"); echo 'Comments were deleted!'; } Link to comment https://forums.phpfreaks.com/topic/148817-solved-process-php-code-on-link-click/#findComment-781543 Share on other sites More sharing options...
acctman Posted March 10, 2009 Author Share Posted March 10, 2009 do i have to rename this to something else <a href="javascript:myAjax(1);"> Link to comment https://forums.phpfreaks.com/topic/148817-solved-process-php-code-on-link-click/#findComment-781574 Share on other sites More sharing options...
The Little Guy Posted March 11, 2009 Share Posted March 11, 2009 do i have to rename this to something else <a href="javascript:myAjax(1);"> Yes, the 1 should be replaced with the objects id in the database. Link to comment https://forums.phpfreaks.com/topic/148817-solved-process-php-code-on-link-click/#findComment-781761 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.