sexytuna
sexytuna

Reputation: 9

Pass php variable to another php page

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>

Upvotes: 0

Views: 126

Answers (3)

ʰᵈˑ
ʰᵈˑ

Reputation: 11375

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;

Upvotes: 2

Ram Sharma
Ram Sharma

Reputation: 8819

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">

Upvotes: 0

Florian
Florian

Reputation: 2874

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.

Upvotes: 0

Related Questions