Jump to content

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

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.