PDA

View Full Version : $_GET['var'] trouble


joop
11-21-2004, 09:50 PM
Hello all (if there are any - well i expect it will grow :D )

I am having trouble with something really stupid....

The easiest way to explain is to show you my code unfortunately there is a lot - so in advance im sorry.

OK there are three pages the first : pre_contact.html


<html>
<head>
<title>Select your contact</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link href="../CSS/preliminary.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000" topmargin="0" leftmargin="0">

<table align="center" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width=14%"></td>
<td width="800" height="200" background="graphic/title_image.jpg" valign="top" >
<table width="803" cellpadding="10">
<tr>
<td width="96" ><font size="12" face="Comic Sans MS"> Contact</font></td>
</tr>
</table>
<table width="803" cellpadding="0">
<tr>

<td width="95"></td>

<td width="660" valign="top"><font size="8" face="Comic Sans MS">inciter.org.uk</font></td>
<tr>
</table>
</td>
<td width=14%"></td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<th width="750" height="25"></th>
<th width="25"><a href="index.html"><img src="graphic/back.jpg" width="25" height="25" border="none"></a></th>
<th width="125"></th>
</tr>
</table>

<table width="100%" border="0" cellpadding="2" cellspacing="3" class="fontstyledefault">
<tr>
<td width="14%" scope="col" valign="top">

</td>
<td width="72%" scope="col" valign="top" align="left">

<FORM NAME="contact" action="contact.php" method="POST">
<TABLE align="center" border="0" cellpadding="3" cellspacing="3" width="676">
<TR>
<TD width="196" align="right" valign="top"> Select Contact: </TD>
<TD width="206" align="center" valign="top">
<SELECT NAME="cont_act">
<OPTION VALUE="support">Support
<OPTION SELECTED VALUE="feedback">Feedback
<OPTION VALUE="complaint">Complaints
<OPTION VALUE="brainstorm">Brainstorm
<OPTION VALUE="volunteer">Volunteer
</SELECT>

</TD>
<td width="244" valign="top"> </td>
</TR>
</TABLE>
<table>
<tr>
<td width="67"></td>
<td width="667" align="center">
<INPUT TYPE="submit" value="Continue">
<INPUT TYPE="reset" value="Reset Selection">
</td>
</tr>
</table>
</FORM>
</td>
<th width="14%" scope="col" valign="top"> </th>
</tr>

</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<th width="725" height="25"></th>

<th width="25"><img src="graphic/back.jpg" width="25" height="25" border="none" usemap="#back"></th>

<th width="25" valign="middle" align="center"><img src="graphic/top.jpg" width="25" height="25" border="none" usemap="#top"></th>


<th width="125"></th>
</tr>
</table>

<map name="back">
<area shape="rect" coords="-2,-13,36,28" href="index.html">
</map>
<map name="top">
<area shape="rect" coords="-1,-2,38,29" href="#" target="_top">
</map>
</body>
</html>



The second, called : contact.php
It's here that everything seems ok.


<!-- PHP BEGINS -->
<?php
$cont_act=$HTTP_POST_VARS['cont_act'];
?>
<!-- PHP ENDS -->

<html>
<head>
<title>Contact inciter.org.uk</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link href="../CSS/preliminary.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000" topmargin="0" leftmargin="0">

<table align="center" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width=14%"></td>
<td width="800" height="200" background="graphic/title_image.jpg" valign="top">
<table width="803" cellpadding="10">
<tr>
<td width="96"><font size="10" face="Comic Sans MS"> Contact</font></td>
</tr>
</table>
<table width="803" cellpadding="0">
<tr>

<td width="95"></td>

<td width="660" valign="top"><font size="8" face="Comic Sans MS">inciter.org.uk</font></td>
<tr>
</table>
</td>
<td width=14%"></td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<th width="750" height="25"></th>
<th width="25"><a href="pre_contact.html"><img src="graphic/back.jpg" width="25" height="25" border="none"></a></th>
<th width="125"></th>
</tr>
</table>

<table width="100%" border="0" cellpadding="2" cellspacing="3" class="fontstyledefault">
<tr>
<td width="14%" scope="col" valign="top">

</td>
<td width="72%" scope="col" valign="top" align="left">

<?php
echo '<FORM NAME="contact" action="process_contact.php?$cont_act=$cont_act" method="POST">
<TABLE align="center" border="0" cellpadding="3" cellspacing="3" width="676">
<TR>
<TD align="right" width="154">Contact:</TD>
<TD width="501">';

if(!$cont_act)
{
echo "Failed to process contact selection !";
}
else
{
echo $cont_act." "; // don't ask - i get a parse error unexpected ';' on line X (if i do not put the " " before ';')

}

echo '</TD></TR></TABLE>
<TABLE align="center" border="0" cellpadding="3" cellspacing="3" width="676">
<TR>
<TD> <font color="green">TODO: Add details in relation to contact
selected.</font>';

switch($cont_act)
{
case 'support' :
echo '<br>Support details <br />';

break;
case 'feedback' :
echo '<br>feedback details <br />';
break;
case 'complaint' :
echo '<br>complaint details <br />';
break;
case 'brainstorm' :
break;
case 'volunteer' :
echo '<br>volunteer details <br />';
break;
default :
echo '<br>failed to process information <br>regarding your contact selection <br />';
break;
}

echo '</TD></TR></TABLE>
<TABLE align="center" border="0" cellpadding="3" cellspacing="3" width="676">
<TR>
<TD align="right" width="156">*First Name:</TD>
<TD width="499">
<INPUT TYPE="text" size="30" name="f_name"></TD>
<TR>
<TD align="right" width="156">*Last Name:</TD>
<TD width="499">
<INPUT TYPE="text" size="30" name="l_name"></TD>
</TR>
<tr>
<TD align="right" width="156">*E-Mail Address:</TD>
<TD width="499">
<INPUT TYPE="text" size="40" name="email"></TD>
</tr>

</TABLE>
<table align="center" width="676">
<tr>
<td width="160" align="right">Subject:</td>
<td><INPUT TYPE="text" size="40" name="subject"></td>
</tr>
<tr>
<td width="160" align="right" valign="top">Comments: </td>
<td align="left" width="504">
<TEXTAREA NAME="comments" ROWS="10" COLS="55" WRAP></TEXTAREA>
</td>
</tr>
</table>
<table>
<tr>
<td>
<INPUT TYPE="submit" value="Submit Message">
<INPUT TYPE="reset" value="Reset Message">
</td>
</tr>
</table>
</FORM>';
?>
</td>
<th width="14%" scope="col" valign="top"> </th>
</tr>

</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<th width="725" height="25"></th>

<th width="25"><img src="graphic/back.jpg" width="25" height="25" border="none" usemap="#back"></th>

<th width="25" valign="middle" align="center"><img src="graphic/top.jpg" width="25" height="25" border="none" usemap="#top"></th>


<th width="125"></th>
</tr>
</table>

<map name="back">
<area shape="rect" coords="-2,-13,36,28" href="pre_contact.html">
</map>
<map name="top">
<area shape="rect" coords="-1,-2,38,29" href="#" target="_top">
</map>
</body>
</html>



The next page seems to fail to recieve the variable $cont_act i don't really understand whats supposed to happen, when or even where.

This final page is called : process_contact.php


<?php

//experiment

//create short variable names

$f_name=$HTTP_POST_VARS['f_name'];
$l_name=$HTTP_POST_VARS['l_name'];
$email=$HTTP_POST_VARS['email'];
$comments=$HTTP_POST_VARS['comments'];
$subject=$HTTP_POST_VARS['subject'];

$mail_content = 'Customer name: ' .$f_name." ".$l_name."\n"
.'Customer e-mail: ' .$email."\n"
."Customer comments: \n".$comments."\n";


switch($_GET['cont_act'])
{
case 'support' :
$toaddress='support@inciter.org.uk';
break;
case 'feedback' :
$toaddress='feedback@inciter.org.uk';
break;
case 'complaint' :
$toaddress='complaints@inciter.org.uk';
break;
case 'brainstorm' :
$toaddress='brainstorm@inciter.org.uk';
break;
case 'volunteer' :
$toaddress='volunteer@inciter.org.uk';
break;
default :
$toaddress='geoff@inciter.org.uk';
break;
}

$fromaddress = 'inciter.org.uk';
mail($toaddress, $subject, $mail_content, $fromaddress);
?>

<html>
<head>
<title>Contact processed</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link href="../CSS/preliminary.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000" topmargin="0" leftmargin="0">

<table align="center" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width=14%"></td>
<td width="800" height="200" background="graphic/title_image.jpg" valign="top" >
<table width="803" cellpadding="10">
<tr>
<td width="96" ><font size="12" face="Comic Sans MS"> Contact</font></td>
</tr>
</table>
<table width="803" cellpadding="0">
<tr>

<td width="147"></td>

<td width="648" valign="top"><font size="12" face="Comic Sans MS">status</font></td>
<tr>
</table>
</td>
<td width=14%"></td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<th width="750" height="25"></th>
<th width="25"><a href="index.html"><img src="graphic/back.jpg" width="25" height="25" border="none"></a></th>
<th width="125"></th>
</tr>
</table>
<table width="100%" border="0" cellpadding="2" cellspacing="3" class="fontstyledefault">
<tr>
<td width="14%" scope="col" valign="top"></td>

<td width="72%" scope="col" valign="top" align="left"> Thankyou for contacting
inciter your mail has been sent to
<?php
echo $cont_act;
echo 'at the e-mail address : ' .$toaddress;
?> with success.</td>
<td width="14%" scope="col" valign="top"></td>
</tr>
</table>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<th width="725" height="25"></th>

<th width="25"><img src="graphic/back.jpg" width="25" height="25" border="none" usemap="#back"></th>

<th width="25" valign="middle" align="center"><img src="graphic/top.jpg" width="25" height="25" border="none" usemap="#top"></th>


<th width="125"></th>
</tr>
</table>

<map name="back">
<area shape="rect" coords="-2,-13,36,28" href="index.html">
</map>
<map name="top">
<area shape="rect" coords="-1,-2,38,29" href="#" target="_top">
</map>
</body>
</html>


Again sorry for the length in message. Thanks for any input :-)
[/b]

Anonymous
11-21-2004, 10:31 PM
The query string is there, but you're using post as the method. So, you could try changing the method to "GET" instead, and see if that works. May not though, but it's worth a try. (In contact.php)

<?php
echo '<FORM NAME="contact" action="process_contact.php?$cont_act=$cont_act" method="POST">



Just a recommendation, use isset() to check to make sure it's set. Like this, in process_contact.php.

if (isset($_GET['type']) and $_GET['type'] != "") {
switch($_GET['cont_act'])
{
...
}
}


That checks to make sure, first, if it's set, and second if it's empty.


One problem may be your PHP version. If it's less than 4.1.0, you'll need to use $HTTP_GET_VARS. So check that.


Are there any errors, or is it $cont_act just plain empty?

joop
11-21-2004, 10:38 PM
It's just empty

Which really frustrating - i would find it easier if i could debug more affectively but i have no idea about that yet.

Thanks i think i know what you meen i'll give it a go.

My Hosts version is PHP Version 4.3.9

joop
11-21-2004, 11:04 PM
Ok i tried it with GET in place of post unfortunatly i recieved an error. Thanks again.

Do you have any other ideas?

Zykaz
11-21-2004, 11:07 PM
Did you try isset()?

And what's your PHP version?

joop
11-22-2004, 08:26 AM
I've just tried isset()
I get this now -

No recipient addresses found in header

The code changes were...


if(!isset($_GET['cont_act']))
{
echo "failed to retrieve data";
}
else
{
switch($_GET['cont_act'])
{
case 'support' :
$toaddress='support@inciter.org.uk';
break;



PHP Version is 4.3.9

Zykaz
11-22-2004, 09:50 AM
Ok, lets try two more things,...

It really could be a server issue. I'm guessing the server is running Linux?

First, check the permissions on the three files. They'll need to be chmod'ded to 666 or 777,...

The error could be a problem with the server's sendmail program (providing that's what it's running).

Here's a quote from another forum:

Re: No recipient addresses found in header

That message means that you have your "Administrator Blind Carbon-Copy" set to On in the "configure" section of ApplyRefer and the host that is hosting your site is using a version of sendmail that checks for a valid recipient
name each time it sends out mail. When it doesn’t find a valid recipient name, it pops that warning message up. This will not affect you from using ApplyRefer of from your users sending mail its just a warning.

You can stop this message from appearing by turning Off your "Administrator Blind Carbon-Copy" feature (which sends a copy of each email sent from your site to you) in the configure section of ApplyRefer.

Regards,
Support
ApplyTools.com


Try going through what this guy says, to see if it's actually just the server. If that doesn't work, then I'll go through your code line-by-line and try to get it figured out.

(Don't you love debugging? :p)

joop
11-22-2004, 10:36 AM
Yes they are using Linux :-)

They wrote back to me regarding something else that accured :

-------------------------------------------------------------------------------------

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@inciter.org.uk and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.

Apache/2.0.51 (Red Hat) Server at www.inciter.org.uk Port 80

They wrote:

-------------------------------------------------------------------------------------

We're currently having some problems with the authentication server, which is causing PHP CGI scripts and reseller account registrations to fail. We've just put a message on the system status page to that effect. We're working on the problem and will have everything back to normal as soon as possible.

Thanks for your patience and apologies for the inconvenience,

Paul Wood.
Heart Internet Support.

-------------------------------------------------------------------------------------

Im gonna have to wait on them now i'll get back to you asap

joop
11-22-2004, 06:48 PM
Ok with appologese - i am fully aware of this taking up your time - you have no idea how much support you have been (Ive needed it) and Thank you.

I don't think i have access to change any of the php settings unless that file i have .htaccess lets me (think i read somewhere thats the way) alows me.


First, check the permissions on the three files. They'll need to be chmod'ded to 666 or 777,...


How do i check this ive already had a look in the phpinfo(), i see nothing relating to that.


The error could be a problem with the server's sendmail program (providing that's what it's running).


I have been successfull in sending mail to myself using the :


mail($toaddress, $subject, $mail_content, $fromaddress);

It was just being sent to the default value applied via the switch statement.

I pretty sure is a case of, there is no value in my variable.

Can i access it using an array number?

joop
11-22-2004, 06:56 PM
The other large hint that its the data contents not existing is now that i am trying to access it using GET it returns nothing - not even the default value in the switch statement returns true.

I have looked to see if im allowed to use the GET feature (think its called a Superglobal) and its a yes.

You can see this list of phpinfo() if you like at my site www.inciter.org.uk
And click the Shop@inciter.org.uk.

Zykaz
11-22-2004, 08:43 PM
Yes, superglobals. That's why I asked the PHP version earlier, anything under 4.1.0, and you wouldn't be able to use $_GET[]. 4.1.0 was the version superglobals were implemented. You _could_ try using $HTTP_GET_VARS['cont_act'], but I doubt that'll make a difference.

.htaccess isn't for individual file permissions. If you're uploading with FTP, then you'll probably be able to change the permissions in that, providing that your host allows it. Try right clicking, or looking around for a 'chmod' command, and if it asks for a value, put in 777. If your FTP program doesn't support it, then it'll have to be changed through another PHP page, that I could put together.

You can't access it with an array, considering it's a _just_ a variable, not an array.

Ah, I didn't realize that the default wasn't even going (sorry if you already said that and I missed it). I was under the impression that it was at least using the default email. Well then, it must be either the code, or the permissions, then (more likely the code). And I will go through it all either tonight or tomorrow.

One way that you can try debugging the code, is by adding print statements that print $cont_act, at the end of each page, maybe, and making sure it prints out. If it prints on the second page, but not the third, then it is obviously coding error. Try that, and let me know what you get.

joop
11-22-2004, 09:15 PM
process_contact.php returns absolutely nothing with the print function but the other page contact.php does.

Here's the code where ive made the changes.

<?php

//experiment

//create short variable names

$f_name=$_POST['f_name'];
$l_name=$_POST['l_name'];
$email=$_POST['email'];
$comments=$_POST['comments'];
$subject=$_POST['subject'];

$mail_content = 'Customer name: ' .$f_name." ".$l_name."\n"
.'Customer e-mail: ' .$email."\n"
."Customer comments: \n".$comments."\n";

if(!isset($_GET['cont_act']))
{
echo 'failed to retrieve data <br>';
}
else
{
switch($_GET['cont_act'])
{
case 'support' :
$toaddress='support@inciter.org.uk';
break;
case 'feedback' :
$toaddress='feedback@inciter.org.uk';
break;
case 'complaint' :
$toaddress='complaints@inciter.org.uk';
break;
case 'brainstorm' :
$toaddress='brainstorm@inciter.org.uk';
break;
case 'volunteer' :
$toaddress='volunteer@inciter.org.uk';
break;
default :
$toaddress='geoff@inciter.org.uk';
echo '<BR>'.$_GET['cont_act'];
break;
}
}

$fromaddress = 'inciter.org.uk';
mail($toaddress, $subject, $mail_content, $fromaddress);
?>

Ive tried vareous ways :-

$_GET[$cont_act]

$_GET[cont_act] // not tried that one lol

$_GET["cont_act"]

$_GET["$cont_act"]

joop
11-22-2004, 09:33 PM
Ive kinda successfully put the GET in place of the post (in the file contact.php)as follows:


<?php
echo '<FORM NAME="contact"
action="process_contact.php?$cont_act=$cont_act"
method="$_GET[$cont_act]">


it outputs the following in process_contact.php URL

http://www.inciter.org.uk/process_contact.php?f_name=G&l_name=Lord&email=inc iter@tiscali.co.uk&subject=Test&comments=test

joop
11-22-2004, 11:27 PM
I havn't successfully passed the variable lol sry if i gave that impression.

Zykaz
11-22-2004, 11:29 PM
Heh.

Using method="$_GET['cont_act']" isn't going to work, because that isn't an actual method. Just plain GET is what you're probably going to want.

Actually, post your address bar after each page has been executed.

Zykaz
11-23-2004, 09:49 PM
Ok, I went through the code. I didn't see anything that I thought could cause this. However, I have a question for you.

Here:

<FORM NAME="contact" action="process_contact.php?$cont_act=$cont_act" method="POST">


What's the use of '?$cont_act=$cont_act'? You could just change it to:

<FORM NAME="contact" action="process_contact.php" method="GET">


And it would most likely work the same (maybe it _would_ actually work, though), unless you need the query string for something and I just missed it?

By the way, with the conditional isset(), does it output "failed to retrieve data"?

One last thing: Tonight is the last night that I'll be in-state. I'm leaving tomorrow morning for PA, and I'm not sure about computer access. I'll get on here in the early morning, and I'll try to when I'm in PA. So if I don't post in here until Saturday, don't think I forgot about you.

joop
11-24-2004, 01:05 AM
Yes i have already cought on with using GET in place of POST

Ive got it running now - thank you very very very much you have been a great help (rare). I removed the pre_contact and have used GET for the whole form - i noticed i was trying to use the get to get a variable from the previouse page only to find that it actually sends an array of all the variables inside that form.

Thanks again - i can now work on some simple dynamic features on the contact.php. Here we go........

PS...
When ive had some sleep i'll return and post the final results of success that i have.