Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.