Jump to content

[SOLVED] Process php code on link click?


acctman

Recommended Posts

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

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!';     
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.