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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.