transparencia Posted January 15, 2010 Share Posted January 15, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/188625-passing-hidden-value-between-scripts/ Share on other sites More sharing options...
AngelG107 Posted January 15, 2010 Share Posted January 15, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188625-passing-hidden-value-between-scripts/#findComment-995831 Share on other sites More sharing options...
Felex Posted January 15, 2010 Share Posted January 15, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188625-passing-hidden-value-between-scripts/#findComment-995837 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.