yobo Posted August 5, 2012 Share Posted August 5, 2012 Hey Guys, I am having a strange issue I have a form where a user can enter there name and it will echo it out on the next page (it is a bigger script but i am doing some testing bit by bit) The form page <form action="includes/runtime.php" method="post"> <p>Asset ID: <input type="text" name="asset_id" size="15" maxlength="20" value="<?php echo $_GET['asset_id'];?>" /></p> <label>Select Hardware Type:</label><select name="hw_type"> </select> <input type="hidden" name="rma_status" size="20" maxlength="20" value="New"/> <p>Submitter Name: <input type="text" name="name" size="20" maxlength="20"/></p> <p>Fault Description: <textarea name="fault_desc" rows="20" cols="30"></textarea></p> <p><input type="submit" name="submit" value="Add Record" /></p> <input type="hidden" name="newrma" value="new"/> </form> and the runtime page code foreach ($_POST as $key => $value) { $post[$key] = $value; echo $post['name']; } basically it echos the value of name but outputs 4 copies for example if i added name john it would output JohnJohnJohnJohn I only need it to output the once any ideas J Link to comment https://forums.phpfreaks.com/topic/266715-php-post-echo-multiple-values/ Share on other sites More sharing options...
Barand Posted August 5, 2012 Share Posted August 5, 2012 then put the echo statement after the loop Link to comment https://forums.phpfreaks.com/topic/266715-php-post-echo-multiple-values/#findComment-1367034 Share on other sites More sharing options...
Christian F. Posted August 6, 2012 Share Posted August 6, 2012 The reason it ouputs the name 4 times, is because there are four elements in the $_POST array. That means that PHP will run through the content of the foreach () block 4 times, and since echo $_POST['name'] is inside that block... Well, I think the rest should be quite obvious. Link to comment https://forums.phpfreaks.com/topic/266715-php-post-echo-multiple-values/#findComment-1367274 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.