Jump to content

Problem with a form not sending where its ment to...


ericburnard

Recommended Posts

Hey there. First of here is my problem code

 

?
include ('db.php');

mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM departments";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "

<form name='dep' action='login2.php?page=6&dep=$department' method='get'>
<select name='dep'>";

$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$department=mysql_result($result,$i,"department");

echo "

<option value='$department'>$department</option>
";

$i++;
}	
?>

</select>
<input type="submit" value="Go">
</form>

 

Ass you can see, i am wanting to send my form to 'login2.php?page=6&dep=$department'  The problem that im having is that it is only sending the user to 'login2.php?dep=(whatever department they chose)'

I have tried allsorts from taking the name='dep' out of the select bit to changing the method of the form to 'post' (usin post will send it to the right page but it wont diplay the value chose in the dropdown box on the page before)

Im sure its something really stupid that ive missed or done wrong but its starting to bug me now!!!

Any help please :)

 

Eric x

Link to comment
Share on other sites

When you use method="get", the form data replaces anything you have already put after the URL in the action="..." parameter.

 

Just put hidden fields in the form with the page=6&dep=$department values -

 

echo "<input type=\"hidden\" name=\"page\" value=\"6\">
<input type=\"hidden\" name=\"dep\" value=\"$department\">";

 

Or use the POST method.

Link to comment
Share on other sites

When you use method="get", the form data replaces anything you have already put after the URL in the action="..." parameter.

 

Just put hidden fields in the form with the page=6&dep=$department values -

 

echo "<input type=\"hidden\" name=\"page\" value=\"6\">
<input type=\"hidden\" name=\"dep\" value=\"$department\">";

 

Or use the POST method.

 

Thats worked!! thanks!! Just one more problem has arrisen its now sending to this link

http://ericburnard.freehostia.com/login2.php?page=6&dep=&dep=Admin

There is one dep to many in the address

Link to comment
Share on other sites

ok i have fixed the last problem. I numbered all of the deps that were in the form and then deleted the ones that wernt needed in the address box.

Now im having a problem with getting the dep value from the address box even though it worked before!!

$depart=$_GET["dep"];

That is what im using which is correct, right? So every time i paste $depart it should display the value from the address box

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.