PHP GET variable problems

liunx

Guest
I'm trying to code a script that has many different modules in it, and to determine which module I'm in, I use get variables heres my code:

if ($_GET["p"] == "single_email") //section of the code for a single email
{
if ($_GET["a"] == "send") //if the user filled out the form and is ready to send
{
$conn = mysql_connect("localhost", "username", "pass") or die (mysql_error()); //connects to mysql
mysql_select_db("database", $conn) or die (mysql_error()); //selects what data base to use

$sql = "select * from mail_logins where login = '{$_SESSION["login"]}'"; //creates the query
$result = mysql_query($sql, $conn) or die (mysql_error()); //issues the query

if (mysql_num_rows($result) == 1) //if the user is logged in
{
$from_email = mysql_result($result, 0, 'from_email'); //gets the users first name
$reply_email = mysql_result($result, 0, 'reply_email'); //gets the users first name

$headers = "From: $from_email\n"; // From address
$headers .= "Reply-To: $reply_email\n"; // Reply-to address
$headers .= "Organization: none\n"; // Organisation
$headers .= "Content-Type: text/html; charset=iso-8859-1\n"; // Type

mail ($_POST["recipient"], $_POST["subject"], $_POST["message"], $headers );

print "<script language=javascript>setTimeout(\"top.location.href = 'http://www.htmlforums.com/archive/index.php/index.php?a=main'\",2000);</script>";
print "The email was sent!\n";
}
else //if the user doesn't exhist, send him back
{
print "<script language=javascript>setTimeout(\"top.location.href = 'http://www.htmlforums.com/archive/index.php/index.php?a=&e=login'\",1000);</script>";
}

}
else //if the user hasn't filled out the form yet
{
print "<form method=POST action=\"modules.php?p=single_email&a=send\">\n";
print "Recipient: <input type=text name=recipient><br>\n";
print "Subject: <input type=text name=subject><br>\n";
print "Message:<br> <textarea name=message rows=30 cols=40></textarea><br>\n";
print "<input type=submit> <input type=reset>\n";
print "</form><br><br><br>\n";
}
}


I can get to the first page, the email form, but when I fill out the form, I get a blank page. I found that my problem lies somewhere with the GET variable "a". Any ideas?

Thanks
AlexWhat is the version of PHP ur having?
if its older than 4.1 then _GET global varibale wont work

try $HTTP_GET_VARS[] insteadI'm using 4.3, I think the problem is in my code somwhere, do I have to run the variables through a deconstructor in each mondule maybe? I'll look up how to erase variables, and I'll also try and maybe set the variable back to 0 in each module.

Thanks for the help,
Alexif you fill out a form as POST then GET will not work. you have to use $_POST[""]Good catch scott
i didnt notice that the form is being posted via POST.
;)Good catch scott
i didnt notice that the form is being posted via POST.
;)If you look at the form tag's action attribute you will see his is passing the a variable through the URI (or at least attempting to). However, I for one wouldn't like to comment as to whether a HTTP request can contain both POST and GET headers (go read the RFC's if you really want to know). Really those vars he is passing through the URI should be hidden form elements which are also submitted with the form.Even if the form is posted via POST and if the action contains query string, then the variables of the query string could be received by $HTTP_GET_VARS or $_GET ..(never tried it)

Rain Designs:
Try to debbuge ur code.make use of print statments in side ur loops and see wht the output is like
ie


if ($_GET["p"] == "single_email") //section of the code for a single email
{

echo "INSIDE single mail" ;
if ($_GET["a"] == "send") //if the user filled out the form and is ready to send
{

echo "inside send" ;
..


if (mysql_num_rows($result) == 1) //if the user is logged in
{
echo "user is logged in.." ;*sigh* don't bother with the GET. It's pointless in this context. Add two hidden form elements to the form (one for 'p' and one for 'a'), post them with the form. Why use GET here?Originally posted by Rain Designs
I'm using 4.3, I think the problem is in my code somwhere, do I have to run the variables through a deconstructor in each mondule maybe? I'll look up how to erase variables, and I'll also try and maybe set the variable back to 0 in each module.

Thanks for the help,
Alex
well I didn't see the action of the form. yes it should send both variables but I agree with Torrent as to use those as hidden variables. but it should work as it is coded so make sure your register_globals is set to OFF.I'm not so sure it will work as it is written as part of the HTTP header is whether it is a POST or GET request. I can't imagine that you can have them combined. Anyway, there really is no benefit of choosing GET over POST in this instance.yes it does work, I use it like that sometimes. well, in my project, but its going to be changed, so I know it works :)

but I agree the POST is the way to go.thanks for all the replies! I was actually thinking to just add a hidden form in there. I'll try it out and post my results!

Thanks for all the help,

AlexOriginally posted by scoutt
yes it does work, I use it like that sometimes. well, in my project, but its going to be changed, so I know it works :)

but I agree the POST is the way to go. Just reading RFC2616 I think that if this does work it is more by luck than design. The specification appears to state that that a header is constructed of a single method type (and goes on to list those methods such as HEAD, PUT, POST, GET):5.1.1 Method

The Method token indicates the method to be performed on the
resource identified by the Request-URI. The method is case-sensitive.

Method = "OPTIONS" ; Section 9.2
| "GET" ; Section 9.3
| "HEAD" ; Section 9.4
| "POST" ; Section 9.5
| "PUT" ; Section 9.6
| "DELETE" ; Section 9.7
| "TRACE" ; Section 9.8
| "CONNECT" ; Section 9.9
| extension-method
extension-method = token
You decide what the HTTP request is through the method you invoke. For example, a GET header would look something like:

GET /pub/WWW/ HTTP/1.1
Host: <!-- w --><a class="postlink" href="http://www.w3.org">www.w3.org</a><!-- w -->

Whereas a POST header would have the POST as the method, and not GET. Only one method can be specified as the specification goes on to state the recipient device must respond with "METHOD NOT ALLOWED" where a request contains a METHOD not supported by that device. It could not do this if multiple methods were permissable within the header.

There appears to be no way that multiple requests (read methods) can be initiated from within a single request. I would say this is why Rain Designs mixture doesn't work. Perhaps some servers can handle it but I would say this would be unreliable, and unsupported functionality.


For a thoroughly rivetting read, take a look here:

<!-- m --><a class="postlink" href="http://www.ietf.org/rfc/rfc2616.txt">http://www.ietf.org/rfc/rfc2616.txt</a><!-- m -->

:)well that may be true, but I have never had it fail yet. *knock on wood* :)I think what we see though is it working on your server, but not on Rain Designs, and I think that is the danger; it's inconsistent.

Also, what are you using it for? I've tried to think of every plausible reason someone would need to specify a GET and POST header simultaneously in a single request, but just can't think of any.the same thing he used it for. at the time it was fast and convenient. and like I said, I am going to change it to be hidden variables. generally it was from a copy and paste. :) jsut copied the worng part. :P
 
Back
Top