Forum Moderators: coopster

Message Too Old, No Replies

newbie stuck... please help

         

Acternaweb

7:34 pm on Mar 4, 2005 (gmt 0)

10+ Year Member



What am I doing wrong? I have a form and a php script. The from has a select option. I am not able to have it displayed on the "results page."

here is the HTML page:

<td style="border: 1pt dotted #000000"><select name="country">
<option>select your country
<OPTION VALUE="U.S.">U.S. </option>
<OPTION VALUE="Mexico">Mexico </option>
<OPTION VALUE="Canada">Canada </option>
<OPTION VALUE="Japan"> Japan </option>
</select></td>
</tr>

here is the php

#!/usr/local/bin/php --
<?php
//file feedback.php
echo "<BR>Name &nbsp;= &nbsp; $name";
echo "<BR>Gender &nbsp;= &nbsp; $gender";
echo "<BR>Address &nbsp;= &nbsp; $address";
echo "<BR>City &nbsp;= &nbsp;$city";
echo "<BR>State &nbsp;= &nbsp; $state";
echo "<BR>Zip&nbsp;= &nbsp; $zip";
echo "<BR>Country &nbsp;= &nbsp; $country";
echo "<BR>Phone &nbsp;= &nbsp; $phone";
echo "<BR>Email&nbsp;= &nbsp; $email";
echo"<BR>Comments &nbsp;= &nbsp; $comment";
echo "<BR>IP Address &nbsp;= &nbsp; $REMOTE_ADDR";
echo "<BR>title &nbsp;= &nbsp; $title";
?>

Appreciate any help.

Timotheos

8:14 pm on Mar 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Acternaweb,

Depending on your form it will either be in $_GET [php.net]['country'] or $_POST [php.net]['country'].

Tim

Acternaweb

9:14 pm on Mar 5, 2005 (gmt 0)

10+ Year Member



Thanks but that didn't work.

I played around with the code, now get a response that says "array" Not sure what that means but my selection still does not appear

grandpa

11:12 pm on Mar 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Just to have a clear picture, can you show us the line from your html document that contains the <form> statement. It probably contains method="post", but would be worth knowing. For now, assuming it is posting, in your php document you need to access the variables - and they would be in an array. That's what you're seeing when you see 'array'. Something like $country = $_POST['country']; should give you the posted value.

Are you getting any of the other variables to dipslay on your php document - $name, $gender,$address, etc.?

Acternaweb

12:36 am on Mar 6, 2005 (gmt 0)

10+ Year Member



HI Grandpa

I believe this is what you are referring to
<form method="post" action="feedback.php" name="feedbackform">

Yes all the other responses are shown in the results page.

I tried using what you wrote, but still get the "array" message.

Thanks for the help

grandpa

11:03 am on Mar 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If I was troubleshooting this on my page, the next step would be to see why $country is still an array instead of a single value as expected. So first, verify that $country is an array and simply doesn't contain the value array.

foreach ($country as $key => $val)
echo "<br>$key $val";
}

If you are displaying all of the countries then the form SELECT statement would be my next area of focus. There, you could try something like
<form method="post" action="feedback.php" name="feedbackform" SIZE="1">, making sure that only a single item is selected from the options.

grandpa

12:38 pm on Mar 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



<kick in the head>

Just posted bum info about the SIZE parameter. It's associated with the INPUT parm. Basically I was trying to say 'ensure that only one option is being selected'. Accepting multiple options would result in array.

Acternaweb

11:55 pm on Mar 6, 2005 (gmt 0)

10+ Year Member



HI Granda Pa -

I added this to the PHP script, now it worked. However I am at a lost as to what it means. How did you know it would work?

foreach ($country as $key => $val)
echo "<br> Country = $val";

Thanks so much for your help and teachings

grandpa

11:04 am on Mar 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



How did you know it would work?
You told me, when you said you were receiving Array in the output.

Here's what I think it means - somewhere you are defining $country as an array. I think you didn't intend to, since you are just trying to pass the variable to a script and display the selection.

Arrays are defined in one of two ways, either with the array construct or by using square-bracket syntax.

$country = array();
or
$country[] = 'Selected Country';

If you are using the brackets (that's my guess), the array will be created if it doesn't exist. You might want to have another look at your form page and see how $country is being populated before it gets posted.

As an aside, you can view the content of $country, or any array, with the print_r function:
print_r($country);

And the output for $country will probably look like this:
Array
( [0] => Selected Country )