Problem passing the correct value in ID to another page

carlmagpie

New Member
I am using a form to edit comments and using the hidden input fields to pass the value, the form is something like this.\[code\]<input type="text" name="name" value="http://stackoverflow.com/questions/3674393/<?php echo $name; ?>" class="input" /><input type="hidden" name="com_name" value="http://stackoverflow.com/questions/3674393/<?php echo $name;?>"/><input type="text" name="email" value="http://stackoverflow.com/questions/3674393/<?php echo $email; ?>" class="input" /><input type="hidden" name="com_email" value="http://stackoverflow.com/questions/3674393/<?php echo $email;?>"/><input type="text" name="phone" value="http://stackoverflow.com/questions/3674393/<?php echo $phone; ?>" class="input" /><input type="hidden" name="com_phone" value="http://stackoverflow.com/questions/3674393/<?php echo $phone;?>"/><input type="text" name="location" value="http://stackoverflow.com/questions/3674393/<?php echo $location; ?>" class="input" /><input type="hidden" name="com_location" value="http://stackoverflow.com/questions/3674393/<?php echo $location;?>"/><input type="hidden" name="com_id" value="http://stackoverflow.com/questions/3674393/<?php echo $id; ?>"/><textarea name="comment" cols="" rows="" class="comment-msg"><?php echo $comment; ?></textarea><input type="hidden" name="com_comment" value="http://stackoverflow.com/questions/3674393/<?php echo $comment;?>"/><input name="com_update_1" type="submit" class="btn-70" value="" /> \[/code\]and i am using the while loop to iterate the value in the form fields. my while loop code is\[code\]$query = "SELECT comments.*, news.title FROM comments JOIN news ON comments.news_id = news.id ORDER BY id DESC LIMIT $from, " . COMM_POST_NUMBER; $result = mysql_query($query);while($row = mysql_fetch_array($result)) { $id = $row['id']; $date = date("d-F-Y", $row['timestamp']); $name = stripslashes($row['name']); $email = stripslashes($row['email']); $phone = stripslashes($row['phone']); $location = stripslashes($row['location']); $comment = stripslashes($row['comment']); $news_id = $row['news_id']; $title = stripslashes($row['title']); $approve = $row['approve'];\[/code\]The Iteration works well and it prints the value from the database perfectly and the hidden input field with value ID holds the correct value in this page i.e(comments.php). but when i want to pass the value to different page \[code\]<form action="action.php" method="post">\[/code\] my trouble starts it takes only the first id when i hit submit. i.e id with value 1 and it refuses to take any other values from id.Here is the code from the view source code of the browser\[code\]<div class="comments-toggle"> <input type="text" name="name" value="http://stackoverflow.com/questions/3674393/My Name is 16" class="input" /> <input type="hidden" name="com_name" value="http://stackoverflow.com/questions/3674393/My Name is 16"/> <input type="text" name="email" value="http://stackoverflow.com/questions/3674393/[email protected]" class="input" /> <input type="hidden" name="com_email" value="http://stackoverflow.com/questions/3674393/[email protected]"/> <input type="text" name="phone" value="http://stackoverflow.com/questions/3674393/919999999999" class="input" /> <input type="hidden" name="com_phone" value="http://stackoverflow.com/questions/3674393/919999999999"/> <input type="text" name="location" value="http://stackoverflow.com/questions/3674393/Somewhere" class="input" /> <input type="hidden" name="com_location" value="http://stackoverflow.com/questions/3674393/Somewhere"/> <input type="hidden" name="com_id" value="http://stackoverflow.com/questions/3674393/16"/> <textarea name="comment" cols="" rows=""class="comment-msg"> </textarea> <input type="hidden" name="com_comment" value=""/> <input name="com_update" type="submit" class="btn-70" value="" /> </div>\[/code\]here is the code from action.php\[code\] if( isset($_POST['com_update'])) { echo $id = $_POST['com_id']; if( isset($_POST['name'])) { echo $name = htmlspecialchars(strip_tags(mysql_real_escape_string($_POST['name']))); $query = "UPDATE comments SET name = '$name' WHERE id = '$id'"; $result = mysql_query($query) or die('Error'); }\[/code\]how do i make it pass the correct id values to action.php?
 
Back
Top