Jump to content

php $post echo multiple values


yobo

Recommended Posts

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

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. ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.