0

Is it possible to pass my unique $comment->comment_id; to another php file? I want to have the same id for the li for that input button. when is clicked I want to pass the variable to the php "/model/editComment.php".

<div class="comment-buttons-holder">
    <ul class="comment-buttons-holder-ul">
        <li id="<?php $comment->comment_id; ?>" class="edit-btn">
            <form action ="/model/editComment.php" method="POST">
            <input>" type="submit" value="edit">
            </form>
        </li>
    </ul

Blockquote

</div>

3 Answers 3

2

Using POST

You've got a form. Use a hidden input.

<input type="hidden" name="comment_id" value="<?php echo $comment->comment_id; ?>" />

On your editCommit.php page, you would;

$intCommentId = (isset($_POST['comment_id']) AND ctype_digit( (string) $_POST['comment_id'] )) ? (int) $_POST['comment_id'] : 0;

Using GET

Append it to the action url in the query string.

<form action="/model/editComment.php?id=<?php echo $comment->comment_id; ?>"

On your editCommit.php page, you would;

$intCommentId = (isset($_GET['id']) AND ctype_digit( (string) $_GET['id'] )) ? (int) $_GET['id'] : 0;
Sign up to request clarification or add additional context in comments.

2 Comments

great! how do get the value in /model/editComment.php?
Awesome. Glad I could help. The way StackOverflow works is, once you've received an answer that has helped and solved your problem, mark it as accepted so it will help others in the future, should they have the same issue.
0

Use

<input type="hidden" name="commentId" value="<?php echo $comment->comment_id; ?>"> 

inside your form to pass a value without showing it to the user.

P.S.:

<input>" type="submit" value="edit">

seems to be false, try:

<input type="submit" value="edit">

And i suggest you to add a name to an input, if it has a value.

Comments

0

change

<form action ="/model/editComment.php" method="POST">
<input>" type="submit" value="edit">

to

<form action ="/model/editComment.php?cid=<?php echo $comment->comment_id; ?>" method="POST">
<input type="submit" value="edit">

2 Comments

echo $comment->comment_id;?
any reason for down voting ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.