tmyonline Posted May 7, 2008 Share Posted May 7, 2008 Hi guys: I can't figure this out. Here's a snippet of my code: ... while ($row = mysql_fetch_assoc($result)) { echo 'Sender: ' . $row['messSender']; $nameVar = $row['messTitle'] . $row['messTime'] . $row['contactID']; $nameVar = str_replace(" ", "_", $nameVar); ?> <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> <?php echo '<input type="submit" name="' . $nameVar . '"' . ' value="Reply" />'; echo '</form>'; echo nl2br($row['messBody']); } if (isset($_POST[$nameVar])) { echo 'nameVar = ' . $nameVar; } Basically, I'm reading information out from MySQL. Currently, my database table contains only two records: X & Y. The problem I have is that when I click on "Reply" for record X, somehow, $_POST[$nameVar] for record X is not defined. When I click on "Reply" for record Y, $_POST[$nameVar] for record Y is defined and display the output as expected. I have examined the source code and the "name" attributes contain different $nameVar for each record. So, $_POST[$nameVar] is supposed to be defined regardless of which "Reply" button I click. However, it only works for Y and not for X. Any ideas ? Thanks. Link to comment https://forums.phpfreaks.com/topic/104582-problem-with-_post/ Share on other sites More sharing options...
kenrbnsn Posted May 7, 2008 Share Posted May 7, 2008 Use a hidden value instead of the name of the submit button. <?php while ($row = mysql_fetch_assoc($result)) { echo 'Sender: ' . $row['messSender']; $nameVar = str_replace(' ','_',$row['messTitle'] . $row['messTime'] . $row['contactID']); echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">'; echo '<input type="hidden" name="nameVar" value="' . $nameVar . '" />'; echo '<input type="submit" name="submit" value="Reply" />'; echo '</form>'; echo nl2br($row['messBody']); } if (isset($_POST['submit'])) { echo 'nameVar = ' . $_POST['nameVar']; } ?> Ken Link to comment https://forums.phpfreaks.com/topic/104582-problem-with-_post/#findComment-535317 Share on other sites More sharing options...
tmyonline Posted May 7, 2008 Author Share Posted May 7, 2008 but this code: echo '<input type="hidden" name="nameVar" value="' . $nameVar . '" />'; would create an extra input field which is not necessary. The purpose of my form is to contain only the "Reply" button and nothing else. Users are not to enter anything. Basically, the code that I have is going to display all the email messages (read out from the database), each message is associated with a "Reply" button. So, if he/she wants to reply to message X, he/she will click on the "Reply" button of that particular message. He/she will not enter anything. Therefore, I don't see how I need that line of code above! Link to comment https://forums.phpfreaks.com/topic/104582-problem-with-_post/#findComment-535354 Share on other sites More sharing options...
wildteen88 Posted May 7, 2008 Share Posted May 7, 2008 That field is not seen. Users wont be able to modify the fields contents. That is why the field type is set to to hidden. Link to comment https://forums.phpfreaks.com/topic/104582-problem-with-_post/#findComment-535358 Share on other sites More sharing options...
tmyonline Posted May 7, 2008 Author Share Posted May 7, 2008 It's not working! Link to comment https://forums.phpfreaks.com/topic/104582-problem-with-_post/#findComment-535364 Share on other sites More sharing options...
kenrbnsn Posted May 7, 2008 Share Posted May 7, 2008 It's not working! This doesn't tell us much. Please explain. Ken Link to comment https://forums.phpfreaks.com/topic/104582-problem-with-_post/#findComment-535371 Share on other sites More sharing options...
tmyonline Posted May 7, 2008 Author Share Posted May 7, 2008 I got it working. Thanks Ken and everyone. Link to comment https://forums.phpfreaks.com/topic/104582-problem-with-_post/#findComment-535375 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.