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
https://forums.phpfreaks.com/topic/71040-solved-_post-help/
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
https://forums.phpfreaks.com/topic/71040-solved-_post-help/#findComment-357181
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
https://forums.phpfreaks.com/topic/71040-solved-_post-help/#findComment-357224
Share on other sites

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.