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
https://forums.phpfreaks.com/topic/57456-performing-actions/
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
https://forums.phpfreaks.com/topic/57456-performing-actions/#findComment-284279
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
https://forums.phpfreaks.com/topic/57456-performing-actions/#findComment-284296
Share on other sites

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.