Forum Moderators: coopster

Message Too Old, No Replies

help with form php

         

appletea

5:51 pm on Jul 27, 2010 (gmt 0)

10+ Year Member



Could anyone point out my mistake in the code below? i gt the error of access forbiden after pressing the submit button.Thanks.

<form name= "theform" method="post" action=<?php"<a href='dothis.php?att=".$row['idCourse']."'";?>

[edited by: appletea at 6:04 pm (utc) on Jul 27, 2010]

enigma1

5:56 pm on Jul 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I believe you need to echo the link.

....action=<?php echo "<a href='dothis.php?att=".$row['idCourse']."'";?>

appletea

6:18 pm on Jul 27, 2010 (gmt 0)

10+ Year Member



Hi,

I have tried ur suggestion of using echo,but then it would give the same error.

Anyango

6:42 pm on Jul 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And what is the HTML that your code prints out for that line (in the browser)?

I think that access forbidden error is on your dothis.php because you said it only happens when you submit. so check that first i would.

Matthew1980

6:52 pm on Jul 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there appletea,

>><form name="theform" method="post" action=<?php"<a href='dothis.php?att=".$row['idCourse']."'";?>

This looks like you are trying to combine a form tag with an anchor tag, which I don't think is actually allowed, I haven't seen it before anyway ;-p

<form name= "theform" method="post" action=<?php echo "dothis.php?att=\"".$row['idCourse']."\";?> >

Try that, this is now just a form tag with the action set to point to a file with querystring attribute "att" and the value of whatever is in $row['idCourse'].

Unless I have misunderstood the context of the page and it should be an anchor tag as opposed to a form tag, could you post the condensed version of the code so that we can see the context of where this is being set?

Cheers,
MRb

appletea

7:50 pm on Jul 27, 2010 (gmt 0)

10+ Year Member



Hi,

I am doing this is as to get the value of what I have submitted at this page to the dothis.php page.Tht's is why I've included the dothis.php?att=".$row['Class']."'";?> as I have different classes in my databases now. Basically i'm just trying to get the value i have submitted by using the class id to dothis.php.

Matthew1980

8:33 pm on Jul 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there appletea,

From what you are describing, doesn't sound like you need a form, it's more likely that you need a link, you can set the query string data from a simple link, there is no need for the form, unless you have some input area's/textareas/radio's etc for the user to input some data to be entered into the DB.

Either that or you can place the value in a hidden field and send that, depends on the context of your page really.

Cheers,
MRb

appletea

8:54 pm on Jul 27, 2010 (gmt 0)

10+ Year Member



Hi Matthew1980,

I guess tht I need the form as I have a list of dropdown menu for the user to input data to be enter into the DB.
I'm basically doing an application of marking attendance in which there would be a list of different class with participants in it. So i need to get the attendance of the partcipants in different class to be submitted. Currently,I have used the disabled function if they pressed a submit button.Hence,if i pressed submit, it would disabled all the submit button of the class attendance tht i hv nw even though i hvn't marked it yet.Tht's why i thought of using get in the form as it would be able to fetch the different class id once i pressed submit.

Matthew1980

9:04 pm on Jul 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there appletea,

So you have a dropdown menu - is it the contents of that, that you are trying to send to the processing file, if that's the case the information is already set in the $_POST array when the submit button is pressed - either that or I am *totally* misunderstanding you, probably the latter - 16 hour day up to yet - tired.

If the code isn't too big, post it (removing the specifics) and we can see if there is anything that can be advised - up to you though, I'm just intrigued now :)

Cheers,
MRb

frobozz

3:23 am on Jul 29, 2010 (gmt 0)

10+ Year Member



Hi there. Unless I'm missing something, it looks like you've got a couple syntax errors here that are the source of your trouble.

Your code:

<form name= "theform" method="post" action=<?php"<a href='dothis.php?att=".$row['idCourse']."'";?>

I believe it should be this:

<form name= "theform" method="post" action="dothis.php?att=<?php echo $row['idCourse']; ?>">

I just built a small CMS that required many instances of exactly this. The PHP code needs to be either fully contained inside action's quote marks, or it needs to fully contain the whole action item.

Not sure why you've got the <a href> in there. The contents of action must be a URL / URI; can't be an object like <a>.

In my example I put the "?att=" outside the PHP assuming that it doesn't change. If this piece would also change dynamically, just move it into the PHP echo text instead (example: "<?php echo '?att=' . $row['idCourse']; ?>").

Make sense?

appletea

8:53 am on Jul 29, 2010 (gmt 0)

10+ Year Member



Thanks frobozz. Tht's the solution that I seeking. Manage to solve the "forbidden page" error. Now I'm trying to figure out on how to get successfully the class id as
the url is now "http://localhost/codes/dothis.php?att= ".Obviously the class id is not passing through the next page. Thanks again for your help.

rocknbil

6:30 pm on Jul 29, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I see this approach a lot. I don't understand it's reasoning. :-) Maybe your data is going into the ether because you're doing both POST and GET.

<form name= "theform" method="post" action="dothis.php?att=<?php echo $row['idCourse']; ?>">

So you'll have to look for $_get['att'], and $_post['everything-else'] or $_REQUEST for either.

Another thing to dislike about this is whenever you have $_GET, you have an ugly query string (URL) in the address bar.

example.com/dothis.php?att=1234

<form name= "theform" method="post" action="dothis.php">
<input type="hidden" name="att" value="=<?php echo $row['idCourse']; ?>">

puts everything in $_POST.