Revising for php and cant seem to get this to print the values out that i want
Any ideas?
Thanks
<form action="revision.php" method="GET">
<input type=“text” name=“number[]”/>
<input type=“text” name=“number[]”/>
<input type=“text” name=“number[]”/>
<input type=“text” name=“number[]”/>
<input type=“text” name=“number[]”/>
<input type="Submit" name="Calcuate"/>
</form>
<?php
if(isset($_GET['number'])){
$amount = count($number);
for($i=0; $i < $amount; $i++){
echo $number[$i];
开发者_如何转开发 }
}
?>
I think the actual problem with your code is that the quotation marks " are wrong you are using “ and ” instead of ". Replace those and everything will work.
EDIT: My answer is completely wrong. See @rmarimon in comments below.
Text fields can't be mapped to an array. You'll have to name them something ugly like "number1", "number2", etc and add them up with $_GET['number1'] + ...
<form action="revision.php" method="GET" enctype="multipart/form-data">
Change form to this. The multipart tag must be used for this
you also need this for file uploads
and for printing use this
foreach ($_GET['number'] AS $key => $value)
{
echo "$key => $value";
}
because the array can be number[1] -> number[3]
It is not in your code but do you have
$number = $_GET["number"]
What you are doing is the correct way. This is similar to this other question.
The way I see it, there's a couple things you should change in your code, first, the names of the fields, you're trying to name them number[0], number[1], number[2] from the looks of it but it won't work that way, try naming them differenty or try to make a FOR cicle to create the fields with those custom names. Second, in order to save the array coming in the $_GET variable into the $number variable you need something like this:
if(isset($_GET['number']))
{
$number = $_GET['number'];
$amount = count($number);
for( $i = 0 ; $i < $amount ; $i++ )
echo $number[$i];
}
Hope this helps, if you're still having problems try posting or describing the context and what you have in mind for the form and the array.
精彩评论