Forum Moderators: coopster

Message Too Old, No Replies

Problem echoing form values

         

bysonary

11:27 am on Feb 5, 2007 (gmt 0)

10+ Year Member



I am having trouble with some code, basically its not working so i just tried to echo to see if the results were there but they aren't what i want is to echo the values of a form.

here is the code for the form.

form.php

[b]
//...[/b]

[b]
<form name="pageski" action="menuadd.php">
Please select the page title to add to the menu below.<br />
<select name="pages">
[/b]
[b]
<?
while ($row = mysql_fetch_array($query,MYSQL_ASSOC))
{
echo "<option>".$row['name']."</option>";
}
}
mysql_close($dbc);
?>
</select>
<br><br>
Now enter the text you want to appear in the menu<br />
<input type="text" name="pname"><br><br />
<input type="submit" name="Submit" value="Add to Menu">
</form>
[/b]

Thats the form, it selects the items in the list from a database and displays them ordered by ASC.

Now when i press submit the menuadd.php file looks like this, ignore the commented out code.

menuadd.php

[b]
<?php
include '/home/www/juttuffi/dbc.php';
$name = $_POST['pages'];
$menuname = $_POST['pname'];
[/b]
[b]
echo $name;
echo $menuname;
[/b]

[b]
//commented out code here
?>
[/b]

Now as you can see all i am trying to do here is echo the values from the forms on the previous page, but for some reason it isnt working, can anyone tell me why?

dreamcatcher

11:34 am on Feb 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are missing a form method:

<form name="pageski" action="menuadd.php">

should be:

<form name="pageski" method="post" action="menuadd.php">

dc

mcibor

2:37 pm on Feb 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As dreamcatcher spotted you were missing method="POST" in form
As I recall this is a required field, but still if you omit it, then browsers will mostly send the data anyway, using the get.

Regards
Michal

bysonary

5:30 pm on Feb 5, 2007 (gmt 0)

10+ Year Member



cheers folks i actually changed it to $_REQUEST and it worked but i changed it to POST now

thanks fo the help there my bad

ksks

6:15 pm on Feb 5, 2007 (gmt 0)

10+ Year Member



Unless I am missing something, I see no values in your <option>...</option>
ie <option value=something>...</option>

dreamcatcher

12:23 pm on Feb 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi ksks, Welcome to Webmaster World. :)

The 'value' attribute is optional and only required if you need to pass a different attribute to the one displayed. For example id numbers instead of names. Examples:

<optional>Cars</optional>
<optional value="1">Cars</optional>

dc

ksks

1:58 pm on Feb 6, 2007 (gmt 0)

10+ Year Member



Thanks...I didn't know that...:)