newbie having trouble with posting my result from an array
so i have a program and when the person selects an animal i need to display the animals name and coresponding age. so what do i need to put in my print statement to display that? i tried ".$_POST[animal]" but that didnt work
<!-- Author: Date: File: lifespans.php Purpose: --> <html> <head> <title>Lifespans</title> <link rel ="stylesheet" type="text/css" href="sample.css" /> </head> <body> <h1>Lifespans</h1> <?php $animal = $_POST['animal']; $animal['Mouse'] = 4; $animal['Queen Bee'] = 5; $animal['Squirrel'] = 20; $animal['Ratlesnake'] = 22; $animal['Pheasant'] = 27; $animal['Mallard Duck'] = 29; $animal['Bear'] = 40; $animal['Box Turtle'] = 123; print ("<p>The life span of the </p>"; ?> <a href="lifespans.html"> Try another animal..</a> </body> </html> |
There is no logic in the posted code.
You have to clear your HTML and the <form> tag. Then go for PHP code. For example, your HTML code should look like this. Code:
<body> |
the html isnt the problem i have another page with the html and the selection menu, my problem is that when i run the code whatever variable is chosen the first letter gets changed to a 1. examle: 1heasant, 1ear, etc...
|
Use a different variable to collect the animal name and for the age.
Code:
$animal = $_POST['animal']; Code:
echo "The life span of " . $animal . " is " . $age[$animal]; |
All times are GMT -5. The time now is 09:33 AM. |