Jump to content

[SOLVED] $_POST help


apot

Recommended Posts

I need help with $_POST

 

I'm trying to pass a variable into a form and cannot get the data from $_FORM using the same variable.  Is this because I can't pass a variable into a form name?

 

$i = 1;

 

<?php

echo "<form><input type=\"text\" name=\"name$i\">";

echo "<input type=\"submit\" name\"submit\" value=\"submit\"></form>";

?>

 

have also tried:

 

$i = 1;

 

<?php

echo "<form><input type=\"text\" name=\"name$i\">";

echo "<input type=\"submit\" name\"submit\" value=\"submit\"></form>";

?>

 

now getting the information:

 

<?php

$name = $_POST['name1'];

echo $name;

?>

 

Is this possible? If not is there another way to do it?

 

thanks

 

 

Link to comment
Share on other sites

yah you are need to define the POST method in your form tags because most browser default to GET

 

i would also suggest escaping you text for the variable

 

echo "<form><input type=\"text\" name=\"name" . $i . "\">";

 

and possable useing a single quote to save on the \ (cant use to many stocks are limited)

 

echo '<form><input type="text" name="name"' . $i . '">';

Link to comment
Share on other sites

I have made all those corrections and now i am trying to get the post info while using a variable.

 

<?php
$i = 1;
$name = $_POST['name$i'];
?>

 

have also tried:

 

<?php
$i = 1;
$name = $_POST['name.$i'];
?>

 

Is this possible?

Link to comment
Share on other sites

print_r($_POST);

 

Or run a loop to see which value exists.

 

<?php
for($i=1;$i<=50;$i++){
   if($_POST['name' . $i]){
   echo $_POST['name' . $i] . " exists<br />\n";
   }
}
?>
<?php
$ran = rand(1,50);
?>
<form method="post">
<input type="text" name="name<?=$ran?>" value="<?=$ran?>">
<input type="submit">
</form>

Link to comment
Share on other sites

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.