Solved

PHP, QueryString variables & subroutines - variable doesn't appear in subroutines...

Posted on 2003-12-02
7
3,820 Views
Last Modified: 2008-02-26
I have a php contact page that submits to itself... the page is called as follows...

contact.php?title=Home-Search-Experts

I use <?php echo "$title"; ?> in various spots throughout the page and it shows up no prob. except in the subroutines...

the code is as follows...

<?php        
   
$mail_path = "/usr/sbin/sendmail -i -t";
   
$mail_to = "info@home-search-experts.com";
   
$mail_subject = "HSE CONTACT US EMAIL";

$check=1;

    ini_set("sendmail_from", $mail_from);
    ini_set("sendmail_path", $mail_path);
   
    if ($sent==$check)
    {
      extract($_POST);
      if( mail($mail_to,$mail_subject,
            "\tName: ".$name.
            "\n\nComments / Questions: \n====================\n".$comments,
            "From: ".$email."\r\n".
            "Reply-To: ".$email."\r\n") )            
        {
                showsuccess($name);
        }
        else
        {
              showerror();    
        }
    }
    else
    {        
      showform();
    }
?>

I cannot use the same call of <?php echo "$title"; ?> in the subroutines - it returns a null value. How do I fix this?

Yes... i'm a newbie. :(

Thanks in advance,


Dean
http://www.dcwebsitedesign.com

0
Comment
Question by:chandldj
  • 4
  • 3
7 Comments
 
LVL 13

Expert Comment

by:lozloz
ID: 9863780
hiya newbie :p

you need to set the variable to available globally (i.e. across the entire script) by using the keyword global, so:

function myfunction($blah) {
  global $title;
// etc
}

better than this, replace all instances of $title with $_GET["title"] it's more secure. you don't need to global this either because it's a 'superglobal'

cheers,

loz
0
 

Author Comment

by:chandldj
ID: 9863975
I changed the applicable liines in the subroutine as follows and I still get nothing...

<FORM METHOD="POST" ACTION="advertise.php?title=<?php echo $_GET['title']; ?>&sent=1" NAME="form1" OnSubmit="return validate();">
<INPUT TYPE="hidden" NAME="title" VALUE="<?php echo $_GET['title']; ?>">

see...

http://www.home-search-experts.com/advertise.php?title=Home-Search-Experts

you'll see the title on the page comes up (Home-Search-Experts), but if you look at the source, there is nothing in the above 2 lines.

What am i doing wrong???

Thanks, Dean

0
 

Author Comment

by:chandldj
ID: 9863998
I marked the subroutine section for you in the code.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 13

Expert Comment

by:lozloz
ID: 9864038
can i see the entire php file?

loz
0
 

Author Comment

by:chandldj
ID: 9864065
<HTML><HEAD><TITLE><?php echo "$title"; ?> - Houses, condos, townhouses, mortgages and more!</TITLE>
<META NAME="keywords" CONTENT="homes,<?php echo "$city"; ?>,<?php echo "$state"; ?>,houses,condos,mortgage,lawyer,townhouses,condominiums,lofts,landscaping,estate,realty,real,mls">
<META NAME="description" CONTENT="<?php echo "$city"; ?>'s homes experts - Find your dream house now plus low mortgages, landscaping, estate lawyers and more!">
<META NAME="robots" CONTENT="noindex">
<link rel="stylesheet" type="text/css" href="nn4hse.css">
<style type="text/css">
@import url(hse.css);
</style>
</HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!--

function validate(){

      if (document.form1.name.value.length <1){
            alert('Please enter your name.');
            document.form1.name.focus();
            return false;
      }
      if (document.form1.city.value.length <1){
            alert('Please enter your city of residence.');
            document.form1.city.focus();
            return false;
      }
      if ((document.form1.province.value == "a") || (document.form1.province.value == "b") || (document.form1.province.value == "c")){
            alert('Please select a province or state.\n(If you are outside of North America please choose the last option - "Other".)');
            document.form1.province.focus();
            return false;
      }
      if (document.form1.email.value.length <1){
            alert('Please enter your email address.');
            document.form1.email.focus();
            return false;
      }
      if (document.form1.comments.value.length <1){
            alert('Please enter your comments and/or questions for us.');
            document.form1.comments.focus();
            return false;
      }
      return true;
}

//-->
</SCRIPT>


<FONT FACE="Arial, Helvetica, Verdana, Times New Roman" COLOR="#FEFGFE" SIZE=1>
<BODY leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 link="#0033FF" alink="#00CCFF" vlink="#0033FF" BGCOLOR="#BBBBBB">

<!-- <?php echo "$title"; ?>, <?php echo "$state"; ?> homes, houses, condos, mortgages and more page start //-->
<TABLE WIDTH=771 CELLPADDING=0 CELLSPACING=0 BORDER=0>
<TR VALIGN="top">
<TD WIDTH=770 BGCOLOR="#FFFFFF"><IMG SRC="images/spacer.gif" WIDTH=770 HEIGHT=1></TD><TD WIDTH=1 ROWSPAN=30 BGCOLOR="#000000"><IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=1></TD></TR>
<TR VALIGN="top"><TD WIDTH=770>
<TABLE WIDTH=770 CELLPADDING=0 CELLSPACING=0 BORDER=0>
<TR VALIGN="top">
<TD WIDTH=770 BGCOLOR="#FFFFFF">
<IMG SRC="images/spacer.gif" HEIGHT=1 WIDTH=770></TD></TR>
<TR VALIGN="top">
<TD WIDTH=770 BGCOLOR="#FFFFFF">
<TABLE WIDTH=770 CELLPADDING=0 CELLSPACING=0 BORDER=0>
<TR VALIGN="top">
<TD WIDTH=5></TD>
<TD WIDTH=415><IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=12><BR><H1><?php echo "$title"; ?><BR><IMG SRC="images/home-search.gif" HEIGHT=19></H1></TD>
<TD WIDTH=350 ALIGN="right"><BR>
<A HREF="http://www.home-search-experts.com/realtors.php?title=<?php echo "$title"; ?>">REALTORS CLICK HERE</A>
&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<B>ADVERTISE</B>
&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<A HREF="contact.php?title=<?php echo "$title"; ?>">CONTACT US</A>&nbsp;&nbsp;&nbsp;<BR>
<BR>
<A HREF="#" onMouseOver="(window.status='Book-mark <?php echo "$title"; ?>!'); return true" OnClick="window.external.AddFavorite('http://www.home-search-experts.com/<?php echo "$title"; ?>','<?php echo "$title"; ?> - Home Searching... Made Easy!')">BOOKMARK US</A>
&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<A HREF="#" onMouseOver="(window.status='Tell a friend about <?php echo "$title"; ?>!'); return true" OnClick="window.open('tell-a-friend.asp?title=<?php echo "$title"; ?>','taf','width=580,height=288,toolbar=0,location=0,top=20,left=20,scrollbars=0,resizeable=0')">TELL A FRIEND</A>
&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<A HREF="links.php?title=<?php echo "$title"; ?>">HSE LINKS</A>&nbsp;&nbsp;&nbsp;<BR>

<IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=10></TD></TR></TABLE></TD></TR>
<TR><TD WIDTH="100%">
<TABLE border="0" cellpadding="0" cellspacing="0" width="100%" background="images/dotted-line.gif">
<tr><td width="100%"><img border="0" src="images/spacer.gif" width="1" height="1"></td></tr></table></td></tr>
<TR VALIGN=top><TD WIDTH="100%" ALIGN="right" BGCOLOR="D0E0D0"><IMG SRC="images/spacer.gif" HEIGHT=3 WIDTH=1><BR>
<IMG SRC="images/spacer.gif" WIDTH=15 HEIGHT=1><B>BUYING A HOME
<IMG SRC="images/spacer.gif" WIDTH=40 HEIGHT=1>SELLING A HOME
<IMG SRC="images/spacer.gif" WIDTH=40 HEIGHT=1>MORTGAGES
<IMG SRC="images/spacer.gif" WIDTH=40 HEIGHT=1>ESTATE LAWYERS
<IMG SRC="images/spacer.gif" WIDTH=40 HEIGHT=1>HOME INSPECTORS
<IMG SRC="images/spacer.gif" WIDTH=40 HEIGHT=1>MOVERS</B><IMG SRC="images/spacer.gif" WIDTH=15 HEIGHT=1><BR>
<IMG SRC="images/spacer.gif" HEIGHT=2 WIDTH=1></B></FONT></TD></TR>
<TR><TD WIDTH="100%">
<TABLE border="0" cellpadding="0" cellspacing="0" width="100%" BGCOLOR="black">
<tr><td width="100%"><img border="0" src="images/spacer.gif" width="1" height="1"></td></tr></table></td></tr>
<TR VALIGN=top><TD WIDTH=770 BGCOLOR="#FFFFFF">
<TABLE WIDTH=770 CELLPADDING=0 CELLSPACING=0 BORDER=0>
<TR VALIGN="top">
<TD WIDTH=432>
<IMG SRC="images/homes.jpg" ALT="Homes <?php echo "$city"; ?>" HEIGHT=144></TD>
<TD WIDTH=338 ALIGN="left" BGCOLOR="306040">
<IMG SRC="images/houses.jpg" ALT="Home Searching... Made Easy!" HEIGHT=144></td></tr></table>
</td></tr>
<TR><TD WIDTH="100%">
<TABLE border="0" cellpadding="0" cellspacing="0" width="100%" BGCOLOR="black">
<tr><td width="100%"><img border="0" src="images/spacer.gif" width="1" height="1"></td></tr></table></td></tr>
<TR VALIGN=top><TD WIDTH=770 BGCOLOR="#FFFFFF">
<TABLE WIDTH=770 CELLPADDING=0 CELLSPACING=0 BORDER=0>
<TR VALIGN="top">
<TD WIDTH=5 BGCOLOR="E9EAE9"><IMG SRC="../images/spacer.gif" WIDTH=5 HEIGHT=1></TD>
<TD WIDTH=760 COLSPAN=5 BGCOLOR="E9EAE9"><IMG SRC="../images/spacer.gif" WIDTH=1 HEIGHT=2><BR>
<IMG SRC="../images/tribullet.gif">&nbsp;&nbsp;<A HREF="http://www.home-search-experts.com">HSE HOME</A>&nbsp;&nbsp;&nbsp;<IMG SRC="../images/tribullet.gif">&nbsp;&nbsp;<A HREF="<?php echo "$title"; ?>"><?php $cityhome = strtoupper($title); echo "$cityhome"; ?></A>&nbsp;&nbsp;&nbsp;<IMG SRC="../images/tribullet.gif">&nbsp;&nbsp;<B>ADVERTISE</B><BR>
<IMG SRC="../images/spacer.gif" WIDTH=1 HEIGHT=2></TD>
<TD WIDTH=5 BGCOLOR="E9EAE9"><IMG SRC="../images/spacer.gif" WIDTH=5 HEIGHT=1></TD>
</TD></TR>
<TR VALIGN="top">
<TD WIDTH=770 COLSPAN=7 BGCOLOR="#494949">
<IMG SRC="../images/spacer.gif" WIDTH=770 HEIGHT=1></TD></TR>
<TR VALIGN="top">
<TD WIDTH=5><IMG SRC="images/spacer.gif" WIDTH=5 HEIGHT=1></TD>
<TD WIDTH=300><IMG SRC="spacer.gif" WIDTH=300 HEIGHT=15><BR>
<H3>Advertisers - Get Targeted Leads!</H3>
Here is your chance to generate more leads, close more sales, and operate more efficiently and cost-effectively, 24 hours a day!
 Our website offers you the chance to market to people who are looking to buy a house!
 They are looking for movers, estate lawyers, home inspectors, landscapers, interior decorators and more!
<BR><BR>
You will be billed on a per-click basis so that if the site doesn't produce, you don't pay!
 We are finishing up our site and working on rates, so if you are interested in tapping in to our resource of home buyers, fill in the form to the right and we will contact you when the site is ready.
<BR><BR>
<H5>Requirements</H5>
<UL>
<LI>You must be a well established, reputable company.<BR><BR>
</UL></TD>
<TD WIDTH=5><IMG SRC="images/spacer.gif" WIDTH=5 HEIGHT=1></TD>
<TD WIDTH=1 BACKGROUND="images/dotted-vertical.gif"><IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=1></TD>
<TD WIDTH=9><IMG SRC="images/spacer.gif" WIDTH=9 HEIGHT=1></TD>
<TD WIDTH=445><IMG SRC="spacer.gif" WIDTH=445 HEIGHT=15><BR>
<?php        
   
$mail_path = "/usr/sbin/sendmail -i -t";
   
$mail_to = "advertise@home-search-experts.com";
   
$mail_subject = "HSE CONTACT US EMAIL";

$check=1;

    ini_set("sendmail_from", $mail_from);
    ini_set("sendmail_path", $mail_path);
   
    if ($sent==$check)
    {
      extract($_POST);
      if( mail($mail_to,$mail_subject,
            "\tName: ".$name.
            "\n\tCompany: ".$company.
            "\n\tEmail: ".$email.
            "\n\tReference Page: ".$title.
            "\n\n\tCity: ".$city.
            "\n\tState / Province: ".$province.
            "\n\tPhone Number: ".$phone.
            "\n\nComments / Questions: \n====================\n".$comments,
            "From: ".$email."\r\n".
            "To: ".$mail_to."\r\n".
            "Reply-To: ".$email."\r\n") )            
        {
                showsuccess($name);
        }
        else
        {
              showerror();    
        }
    }
    else
    {        
      showform();
    }
?>
<TD WIDTH=5><IMG SRC="images/spacer.gif" WIDTH=5 HEIGHT=1></TD>
</TD></TR></TABLE></TD></TR>
<TR><TD WIDTH="100%">
<TABLE border="0" cellpadding="0" cellspacing="0" width="100%" background="images/dotted-line.gif">
<tr><td width="100%"><img border="0" src="images/spacer.gif" width="1" height="1"></td></tr></table></td></tr>
<TR VALIGN=top><TD WIDTH=770 ALIGN="CENTER" BGCOLOR="D0E0D0">
&#169; 2003 - <A CLASS="topnav" HREF="http://www.home-search-experts.com">Home-Search-Experts.com</A>&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;Website design by <A CLASS="topnav" HREF="http://www.dcwebsitedesign.com">DC Website Design</A></TD></TR>
<TR><TD WIDTH="100%" BGCOLOR="black">
<img border="0" src="images/spacer.gif" width="1" height="1"></td></tr></table></td></tr></TABLE><BR><BR>
</BODY></HTML>


<?php
function showform()
{

?>



<!-- subroutine start //-->



<H3>Site Launch Notification Form</H3>
<FONT SIZE=1><A HREF="privacy.htm" TARGET="privacy" OnClick="window.open('privacy.htm','privacy','width=330,height=320,toolbar=0,location=0,top=100,left=290,status=1,scrollbars=1,resizable=1')">View our privacy policy</A><BR></FONT>
<FORM METHOD="POST" ACTION="advertise.php?title=<?php echo $_GET["title"]; ?>&sent=1" NAME="form1" OnSubmit="return validate();">
<INPUT TYPE="hidden" NAME="title" VALUE="<?php echo $_GET["title"]; ?>">
Name: &nbsp;<INPUT TYPE="text" NAME="name" SIZE=30><BR><BR>
Company: &nbsp;<INPUT TYPE="text" NAME="company" SIZE=30><FONT SIZE=1> (optional)</FONT><BR><BR>
City/Town: &nbsp;<INPUT TYPE="text" NAME="city" SIZE=30><BR><BR>
Province/State: &nbsp;<FONT FACE="Courier New, Courier" SIZE="2"><SELECT NAME="province">
<OPTION value="a" SELECTED></OPTION>
<OPTION value="b">--Provinces--</OPTION>
<OPTION value="Alberta">Alberta</OPTION>
<OPTION value="British Columbia">British Columbia</OPTION>
<OPTION value="Manitoba">Manitoba</OPTION>
<OPTION value="New Brunswick">New Brunswick</OPTION>
<OPTION value="Newfoundland">Newfoundland</OPTION>
<OPTION value="Nova Scotia">Nova Scotia</OPTION>
<OPTION value="Northwest Territories">Northwest Territories</OPTION>
<OPTION value="Nunavut">Nunavut</OPTION>
<OPTION value="Ontario">Ontario</OPTION>
<OPTION value="Prince Edward Island">Prince Edward Island</OPTION>
<OPTION value="Quebec">Quebec</OPTION>
<OPTION value="Saskatchewan">Saskatchewan</OPTION>
<OPTION value="Yukon Territory">Yukon Territory</OPTION>
<OPTION value="c">--States--</OPTION>
<option value="Alaska">Alaska</OPTION>
<option value="Alabama">Alabama</OPTION>
<option value="Arkansas">Arkansas</OPTION>
<option value="Arizona">Arizona</OPTION>
<option value="California">California</OPTION>
<option value="Colorado">Colorado</OPTION>
<option value="Connecticut">Connecticut</OPTION>
<option value="District of Columbia">D.C.</OPTION>
<option value="Delaware">Delaware</OPTION>
<option value="Florida">Florida</OPTION>
<option value="Georgia">Georgia</OPTION>
<option value="Hawaii">Hawaii</OPTION>
<option value="Iowa">Iowa</OPTION>
<option value="Idaho">Idaho</OPTION>
<option value="Illinois">Illinois</OPTION>
<option value="Indiana">Indiana</OPTION>
<option value="Kansas">Kansas</OPTION>
<option value="Kentucky">Kentucky</OPTION>
<option value="Louisiana">Louisiana</OPTION>
<option value="Massachusetts">Massachusetts</OPTION>
<option value="Maryland">Maryland</OPTION>
<option value="Maine">Maine</OPTION>
<option value="Michigan">Michigan</OPTION>
<option value="Minnesota">Minnesota</OPTION>
<option value="Missouri">Missouri</OPTION>
<option value="Mississippi">Mississippi</OPTION>
<option value="Montana">Montana</OPTION>
<option value="North Carolina">North Carolina</OPTION>
<option value="North Dakota">North Dakota</OPTION>
<option value="Nebraska">Nebraska</OPTION>
<option value="New Hampshire">New Hampshire</OPTION>
<option value="New Jersey">New Jersey</OPTION>
<option value="New Mexico">New Mexico</OPTION>
<option value="Nevada">Nevada</OPTION>
<option value="New York">New York</OPTION>
<option value="Ohio">Ohio</OPTION>
<option value="Oklahoma">Oklahoma</OPTION>
<option value="Oregon">Oregon</OPTION>
<option value="Pennsylvania">Pennsylvania</OPTION>
<option value="Puerto Rico">Puerto Rico</OPTION>
<option value="Rhode Island">Rhode Island</OPTION>
<option value="South Carolina">South Carolina</OPTION>
<option value="South Dakota">South Dakota</OPTION>
<option value="Tennessee">Tennessee</OPTION>
<option value="Texas">Texas</OPTION>
<option value="Utah">Utah</OPTION>
<option value="Virginia">Virginia</OPTION>
<option value="The Virgin Islands">The Virgin Islands</OPTION>
<option value="Vermont">Vermont</OPTION>
<option value="Washington">Washington</OPTION>
<option value="Wisconsin">Wisconsin</OPTION>
<option value="West Virginia">West Virginia</OPTION>
<option value="Wyoming">Wyoming</OPTION>
<option value="Other">Other</OPTION>
</select></FONT><BR><BR>
Phone Number: &nbsp;<INPUT TYPE="text" NAME="phone" SIZE=30><FONT SIZE=1> (optional)</FONT><BR><BR>
E-mail Address: &nbsp;<INPUT TYPE="text" NAME="email" SIZE=30><BR><BR>
Comments and/or Questions:<BR>
<FONT FACE="Courier New, Courier" SIZE="2"><TEXTAREA ROWS=8 COLS=60 NAME="comments"></TEXTAREA></FONT><BR><BR>
<INPUT CLASS="search" TYPE="submit" VALUE="Send">
<INPUT CLASS="search" TYPE="reset" VALUE="Reset Form">
</DL></FORM></TD>



<!-- subroutine end //-->



<?php
}
?>

<?php
function showerror()
{
?>
<H3>Mail Send Error</H3>
<BR>
We're sorry, but there's been an error sending your mail.
 Please hit the back button and try sending it again.
<BR><BR>
If there is still a problem, you can contact us directly at <A HREF="mailto:advertise@home-search-experts.com">advertise@home-search-experts.com</A>
<BR><BR>
Thank you!</TD>
<?php
}
?>

<?php
function showsuccess($name)
{
?>
<H3>Message Sent!</H3>
<BR>
<?php echo "$name"; ?>,
<BR><BR>
Thank you for your interest in advertising with us!
 We try to answer all of our inquiries within 24 hours.
<BR><BR>
Please feel free to continue browsing our site.
<BR><BR><BR>
The Home Search Experts Team.
</TD>
<?php
}
?>
0
 
LVL 13

Accepted Solution

by:
lozloz earned 60 total points
ID: 9864187
try putting all the $_GET["title"]'s back to $title and have global $title; at the top of the function. also try print_r($_GET); print_r($HTTP_GET_VARS); at the top of the function and somewhere outside the function for some debugging - if i could see the html for this it would help

cheers,

loz
0
 

Author Comment

by:chandldj
ID: 9864240
putting

global $title;

in the subroutine worked... I tried putting that in the main function before and it didn't work.

Thanks for all your help...


Dean
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now