PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hi all....I am new to this forum and php coding. I am designing a website for posting articles where users will be able to post anything and comment to any submitted post. But the problem I am facing is to pass the post id (or any variable) from 1 php file to another. I am using hidden variable concept to pass variabes. Here is the code:
//the variable has to be passed in new.php
[b] <form action="new.php" method="post" enctype="multipart/form-data">[/b]
// $clb[club] is the variable that needs to be passed
[b]<?php $var = $clb[club];
echo "<input type='hidden' id='club' name='club' value='$var' >"; ?>[/b]
// code for taking input from the user
<input type="text" size="50" name="text" id="textfield" />
<select name="what" id="select">
<option selected="selected">act</option>
<option>issue</option>
<option>diss</option>
</select>
<label for="button"></label>
<input name="post" type="submit" id="button" value="post" />
<label for="file"><br />
</label>
<p>Recent posts of club1: </p>
<p>
// I also want $clb[club] to be passed in the file old.php....but even here variables are not passed at all!!!
[b] <?php include("old.php"); ?>[/b]
</p>
</form>
// I have even tried this format...I am passing $var1 in club.php when user clicks the link Friend but same story here
[b]<form action="club.php" method="post" enctype="multipart/form-data">
<?php $var1 = $_POST['club1'];
echo "<input type='hidden' id='club' name='club1' value='$var1' >"; ?>
<a href="club.php">Friend
[/b] </p>
</a>
</form>
Can you tell me what may be the problem...I am retrieving the variables like this:
Thank you very much for the reply. But your solution is for passing user's input to a php file. I have different issue:
Suppose you code a php page, say A.php, whose function is show all posts stored in the database. Each post is accompanied with a text box for others to comment on that post (just like Facebook where you have status instead of post). So on submitting any comment over a post, that text box would call another file, say B.php, which will store the comment in the database along with the unique auto-incrementing ID of that post. The ID would act as the address of the corresponding post. Passing the ID from A.php to B.php when user submits comment is my main problem. Now I hope I am able to make myself clear.
Please suggest me anything that comes in your mind??
<?php
/* This information you get from database */
$post_title = 'Hello world';
//...
$post_id = 3; // unique auto-increment ID for a post
?>
<form action="b.php" method="POST">
<textarea name="comment">leave your comment here</textarea>
<input type="hidden" name="post_id" value="<?php echo $post_id ?>">
<input type="submit">
</form>
Then you can easily store this comment in database