Jump to content

Passing hidden value between scripts


transparencia

Recommended Posts

I have a PHP blog that has a comment view.php page. This page shows all the comments on the database and below each comment a button to delete. I have a delete.php page that actually deletes the comment.

 

How can I pass the comment ID from view.php to delete.php, internally (without using URL) so that delete.php knows which comment to delete?

Link to comment
https://forums.phpfreaks.com/topic/188625-passing-hidden-value-between-scripts/
Share on other sites

you can try something like this :

 

<?php

$id_val = 1;

?>
<form action="delete.php" method="POST">
<input type="hidden" name="del_id" value="<?php echo $id_val; ?>" >
</form>

 

that's the HTML form , it should go in the view.php file

 

<?php

// add your db connection procedure here.

$id = $_POST['del_id'];

$query = "DELETE FROM comments WHERE id='$id'";
mysql_query($query);

?>

 

this should go on the delete.php file

nop, you need some JS code to add your script. you need only one hidden input and a javascript function which runs when link is clicked with onClick attribute.

JS function needs to get the id of link and assign it to hidden input, so on, automatically submit the form

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.