Jump to content

Performing actions


almightyegg

Recommended Posts

I have a message board that is run my certain selected members. These members can Pin items, Lock them and Delete them. Is there any way you can click the link that says 'Lock this thread', 'Delete this thread' or 'Pin/Unpin this thread' and it will perform the action without reloading the page???

 

For instance I would click the delete button and it would delete the infomation from the MySQL database but the information would still be on the screen because it wouldn't have reloaded. Same with if I clicked the link that Locked/Pinned it, it would edit the column in the appropriate row that said No, to Yes meaning it would now be Locked/Pinned.

 

I'm assuming that if this can be done, it won't be using PHP directly???

Link to comment
Share on other sites

why use ajax when a simple get and refresh via a header statement would work.

 

this example would work on all links ok.

<?php session_start();

//database connetion

$query="SELECT from `message` where `message_id`='$message_id' and `id`='$id'";

$result=mysql_query($query);

while($x=mysql_fetch_assoc($result)){

//relly encrypt this and unencript ok.

echo"<a href=''".$_SERVER["PHP_SELF"]."'?message=delete&id=$id&message_id=$message_id'>Delete Message</a>";

if($_GET['message']=="delete"){

$id=$_POST['id'];
$message_id=$_POST['message_id'];

$query2="DELETE from `message` where `message_id`='$message_id' and `id`='$id'";
   $result2=mysql_query($query2);
   
   if(mysql_affected_rows($result2)){
 
   header("location ".$_SERVER['PHP_SELF']." ");  	
}
}
 }
?>

 

 

example 2 no refresh needed ok.

topic.php
<?php

//database connetion

$query="select from message where message_id='$message_id'";

$result=mysql_query($query);

while($x=mysql_fetch_assoc($result)){

echo $x['message'];

echo"<p><p/>";

echo"<a href='delete.php?cmd=delete&message_id=$message_id'>Delete Message</a>";

}
?>


delete.php

<?php session_start();

if($_GET['cmd']=="delete"){


$message_id=$_POST($_GET['message_id']);

$query2="DELETE from message where message_id='$message_id' ";
   $result2=mysql_query($query2) or die("mysql_error()");
   
   if(mysql_affected_rows($result2)){
 
   header("location topic_page.php?message_id=$message_id"); 
   }
}
}
   ?>

Link to comment
Share on other sites

why use ajax when a simple get and refresh via a header statement would work.

I tried your second example, perhaps I entered it all wrong but it came up with many errors that seemed to do with the structure of the code rather than the variables...

 

all AJAX is, is javascript

 

It allows you to retrieve information from the server, HTML or PHP (and other files), then it processes them, and returns your results, then you use JavaScript to decide on what to do with those results.

So does this mean I 100% need to know javascript??

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.