Jump to content

[SOLVED] Vexing T_Variable is driving me nutz - help!


Chezshire

Recommended Posts

Hello everyone, I've tried a few things and whatever is causing my error is just starring me right in the face and I'm just not seeing it. I've played around with the double and single quotes, checked the line terminations, etc. And from what I can tell my code shoudl work but it does  :-[

 

I'm trying to cause the fields which are 'optional' (thread/post & Character(s)) to be not print/echo in the e-mail that is produced if their they are left empty.

 

The following code results in the following error: Parse error: parse error, unexpected T_VARIABLE in /home/content/z/a/n/zanland/html/xpg/modMail/report2.php on line 24.

 

This is line #24:

$msg .= (empty($other)) ? "" : 'ISSUE, COMMENT OR CONCERN: $other  \n \n';

 

 

Full code is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>XPG » Message Confirmed!</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
  <h2>XPG » Message Sent!</h2>

<?php
  $name = $_POST['namePlayer'];
  $topic = $_POST['nameTopic'];
  $other = $_POST['other'];
  $thread_PostID = $_POST['threadPostID'];
  $email = $_POST['email'];
  $name_char = $_POST['nameChar'];


  $to = 'BYRNE <mercurypagen@yahoo.com>, DITKO <chezshire@gmail.com>, LIEFIELD <babsbatgirlfan@yahoo.com>, MILLER <spasmolytica@yahoo.com>, Silvestri<rogue_kiss@yahoo.com>, SIMONSON <vismaior2000@yahoo.com>, WHEDON <scottebarr@optonline.net>, WOLFMAN <ghoogler@gmail.com>';
  $subject = 'XPG » ' . $topic .' ';
  $msg = 'FROM: $name \n \n';
  $msg .= (empty($other)) ? "" : 'ISSUE, COMMENT OR CONCERN: $other  \n \n';
  $msg .= (empty($thread_PostID)) ? "" : 'THREAD/POST: $thread_PostID  \n \n';
  $msg .= 'CHARACTER(S): $name_char  \n \n';

  echo 'Thank you for contacting us ' . $name . ' regarding ' .  $topic . '. <br /><br /> We will discuss this subject and try to have one of XPG’s Staff member contact you regarding this issue within 24 hours. If you have sent a notice that you will be away, this will be done ASAP and you have up to two weeks excused abscence.<br /> Thank you for your patience and understanding while you wait for us to get back to you. <br /> <br />';
?>

<p align=center><a href=../messages.php>RETURN TO XPG</a></p>

</body>
</html>

Link to comment
Share on other sites

There isn't an error on that line:

$msg .= (empty($other)) ? "" : 'ISSUE, COMMENT OR CONCERN: $other  \n \n';

Besides the fact that if you use single quotes your variable $other won't be parsed:

Link to comment
Share on other sites

Hello AlexWD,

  I'm not sure if your being very clever and making a funny or trying to help me out. I'm still new to all of this. I'm starting college this fall and one of my first classes is going to be a PHP intro, etc. Right now I'm just trying to get my little dumb form to work a little better then it does - I think you're saying that line 24 looks ok as it, which would mean there is a problem earlier in the form then (yes?). I've looked through the whole thing and have not been able to find it. Can you help and if so can you say it in a manner a novice such as myself would understand?

 

Thank you for looking  -  it is appreciated.

-Chex

Link to comment
Share on other sites

He's saying if $other is NOT empty it will concatenate $msg with 'ISSUE, COMMENT OR CONCERN: $other  \n \n'; (literally the characters $other).  You need to change the single quotes around that condition to double quotes.

 

If you test out both ways you will see the difference.

Link to comment
Share on other sites

Thank you Maq

  I wasn't able to follow what AlexWD said as I'm just not on his level yet (or yours) but i hope to be one day. Thank you - I'm off to work those quotes (i did try changing them all from single to double but not specific parts to single to double as you/he are suggesting.

 

Thank you!

Link to comment
Share on other sites

That shouldn't be causing your errors. I didn't see anything that should. It's just that if you have a variable within single quotes, it won't output the variables value. It'll evaluate it like a string.

 

$variable = 'Some value';
echo "This variable has the value of $variable"; //Some value
echo 'This variable has the value of $variable'; //$variable

Link to comment
Share on other sites

That shouldn't be causing your errors. I didn't see anything that should. It's just that if you have a variable within single quotes, it won't output the variables value. It'll evaluate it like a string.

 

$variable = 'Some value';
echo "This variable has the value of $variable"; //Some value
echo 'This variable has the value of $variable'; //$variable

 

I agree.  Nothing there should cause an error, even with error_reporting set to max.

 

There are like 5 other lines that need to be changed from single to double quotes.

Link to comment
Share on other sites

Hmms.

    I fear that I'm not understanding ( Makes a sad dumb face )

    I tried what I though you quys were suggesting (see example #1), and got an error - so i deleted lines 24, 25 and 26 to see what would happen and the page worked in that there were no errors (see Example #2), but the message and content wasn't being sent as the handlers for that stuff was deleted from the code.

 

So it seems to me that something is wrong with these three lines, what I don't know but it's what i'm trying to figure today (hopefully)

 

#24:  $msg .= (empty($other)) ? "" : "ISSUE, COMMENT OR CONCERN: $other  \n \n";

#25:    $msg .= (empty($thread_PostID)) ? "" : "THREAD/POST: $thread_PostID  \n \n";

#26:    $msg .= (empty($name_char)) ? "" : "CHARACTER(S): $name_char  \n \n";

 

 

So am i not understanding what needs to be single quoted vs. double quoted or is it that i'm trying to do isn't doable?

 

 

Example 1:

<?php
  $name = $_POST['namePlayer'];
  $topic = $_POST['nameTopic'];
  $other = $_POST['other'];
  $thread_PostID = $_POST['threadPostID'];
  $email = $_POST['email'];
  $name_char = $_POST['nameChar'];


  $to = 'BYRNE <mercurypagen@yahoo.com>, DITKO <chezshire@gmail.com>, LIEFIELD <babsbatgirlfan@yahoo.com>, MILLER <spasmolytica@yahoo.com>, Silvestri<rogue_kiss@yahoo.com>, SIMONSON <vismaior2000@yahoo.com>, WHEDON <scottebarr@optonline.net>, WOLFMAN <ghoogler@gmail.com>';
  $subject = 'XPG » ' . $topic .' ';
  $msg = 'FROM: $name \n \n';
  $msg .= (empty($other)) ? "" : "ISSUE, COMMENT OR CONCERN: $other  \n \n";
  $msg .= (empty($thread_PostID)) ? "" : "THREAD/POST: $thread_PostID  \n \n";
  $msg .= (empty($name_char)) ? "" : "CHARACTER(S): $name_char  \n \n";

  echo 'Thank you for contacting us ' . $name . ' regarding ' .  $topic . '. <br /><br /> We will discuss this subject and try to have one of XPG’s Staff member contact you regarding this issue within 24 hours. If you have sent a notice that you will be away, this will be done ASAP and you have up to two weeks excused abscence.<br /> Thank you for your patience and understanding while you wait for us to get back to you. <br /> <br />';
?>

 

Example two (no errors but the message isn't being delivered, only a notice someone sent an email which is kind of pointless):

<?php
  $name = $_POST['namePlayer'];
  $topic = $_POST['nameTopic'];
  $other = $_POST['other'];
  $thread_PostID = $_POST['threadPostID'];
  $email = $_POST['email'];
  $name_char = $_POST['nameChar'];


  $to = 'BYRNE <mercurypagen@yahoo.com>, DITKO <chezshire@gmail.com>, LIEFIELD <babsbatgirlfan@yahoo.com>, MILLER <spasmolytica@yahoo.com>, Silvestri<rogue_kiss@yahoo.com>, SIMONSON <vismaior2000@yahoo.com>, WHEDON <scottebarr@optonline.net>, WOLFMAN <ghoogler@gmail.com>';
  $subject = 'XPG » ' . $topic .' ';
  $msg = 'FROM: $name \n \n';
  $msg .= (empty($other)) ? "" : "ISSUE, COMMENT OR CONCERN: $other  \n \n";
  $msg .= (empty($thread_PostID)) ? "" : "THREAD/POST: $thread_PostID  \n \n";
  $msg .= (empty($name_char)) ? "" : "CHARACTER(S): $name_char  \n \n";

  echo 'Thank you for contacting us ' . $name . ' regarding ' .  $topic . '. <br /><br /> We will discuss this subject and try to have one of XPG’s Staff member contact you regarding this issue within 24 hours. If you have sent a notice that you will be away, this will be done ASAP and you have up to two weeks excused abscence.<br /> Thank you for your patience and understanding while you wait for us to get back to you. <br /> <br />';
?>

Link to comment
Share on other sites

<?php
  $msg .= (empty($other)) ? "" : "ISSUE, COMMENT OR CONCERN: $other  \n \n";
  $msg .= (empty($thread_PostID)) ? "" : "THREAD/POST: $thread_PostID  \n \n";
  $msg .= (empty($name_char)) ? "" : "CHARACTER(S): $name_char  \n \n";
?>

To:

 

<?php
  $msg .= (empty($other)) ? "" : "ISSUE, COMMENT OR CONCERN: ".$other."  \n \n";
  $msg .= (empty($thread_PostID)) ? "" : "THREAD/POST: ".$thread_PostID."  \n \n";
  $msg .= (empty($name_char)) ? "" : "CHARACTER(S): ".$name_char."  \n \n";

?>

Link to comment
Share on other sites

That shouldn't cause a problem. I even tested it, it worked fine:

 

$other = 'something';
$thread_postID = 550;
$name_char = 'Alex';

$msg .= (empty($other)) ? "" : "ISSUE, COMMENT OR CONCERN: $other  \n \n";
$msg .= (empty($thread_PostID)) ? "" : "THREAD/POST: $thread_PostID  \n \n";
$msg .= (empty($name_char)) ? "" : "CHARACTER(S): $name_char  \n \n";

 

Output: ISSUE, COMMENT OR CONCERN: something CHARACTER(S): Alex

 

I even tested for a syntax error when they're all null, no errors then either.

Link to comment
Share on other sites

  $msg .= (empty($other)) ? "" : "ISSUE, COMMENT OR CONCERN: $other  \n \n";
  $msg .= (empty($thread_PostID)) ? "" : "THREAD/POST: $thread_PostID  \n \n";
  $msg .= (empty($name_char)) ? "" : "CHARACTER(S): $name_char  \n \n";
?>

To:

 

  $msg .= (empty($other)) ? "" : "ISSUE, COMMENT OR CONCERN: ".$other."  \n \n";
  $msg .= (empty($thread_PostID)) ? "" : "THREAD/POST: ".$thread_PostID."  \n \n";
  $msg .= (empty($name_char)) ? "" : "CHARACTER(S): ".$name_char."  \n \n";

?>

 

Yes, either of those should be fine.  But you changed your code from using single quotes to double now...

 

Do you still get errors?  If no, what does $msg look like when you echo it out?

Link to comment
Share on other sites

Whoops, I misnamed a variable on my last example. Still there was no problems..

 

<?php
$other = 'something';
$thread_PostID = 550;
$name_char = 'Alex';

$msg .= (empty($other)) ? "" : "ISSUE, COMMENT OR CONCERN: $other  \n \n";
$msg .= (empty($thread_PostID)) ? "" : "THREAD/POST: $thread_PostID  \n \n";
$msg .= (empty($name_char)) ? "" : "CHARACTER(S): $name_char  \n \n";

echo $msg;

 

ISSUE, COMMENT OR CONCERN: something THREAD/POST: 550 CHARACTER(S): Alex

Link to comment
Share on other sites

Hello AlexWD & MAQ,

 

I found one of my problems - I turned on 'See Invisibles' using TextWrangler and found that some of my character spaces had unique/special fonts in them. I deleted the special characters and test the following code (see below).  I no long get the T_Variable, but I'm not not getting the e-mail either :( So I'm not sure what i've done now. Thoughts? Help?

 

 

 

 

 


<?php
  $name = $_POST['namePlayer'];
  $topic = $_POST['nameTopic'];
  $other = $_POST['other'];
  $thread_PostID = $_POST['threadPostID'];
  $email = $_POST['email'];
  $name_char = $_POST['nameChar'];


  $to = 'BYRNE <mercurypagen@yahoo.com>, DITKO <chezshire@gmail.com>, LIEFIELD <babsbatgirlfan@yahoo.com>, MILLER <spasmolytica@yahoo.com>, Silvestri<rogue_kiss@yahoo.com>, SIMONSON <vismaior2000@yahoo.com>, WHEDON <scottebarr@optonline.net>, WOLFMAN <ghoogler@gmail.com>';
  $subject = 'XPG » ' . $topic .' ';
  $msg = 'FROM: $name \n \n';
  $msg = 'ISSUE, COMMENT OR CONCERN: $other  \n \n';
  $msg .= (empty($thread_PostID)) ? "" : "THREAD/POST: $thread_PostID  \n \n";
  $msg .= (empty($name_char)) ? "" : "CHARACTER(S): $name_char  \n \n";

  echo 'Thank you for contacting us ' . $name . ' regarding ' .  $topic . '. <br /><br /> We will discuss this subject and try to have one of XPG’s Staff member contact you regarding this issue within 24 hours. If you have sent a notice that you will be away, this will be done ASAP and you have up to two weeks excused abscence.<br /> Thank you for your patience and understanding while you wait for us to get back to you. <br /> <br />';
?>

Link to comment
Share on other sites

Well first off:

$msg = 'FROM: $name \n \n';
  $msg = 'ISSUE, COMMENT OR CONCERN: $other  \n \n';

You basically removed the FROM:,

 

Change it to:

 

$msg = 'FROM: $name \n \n';
  $msg .= 'ISSUE, COMMENT OR CONCERN: $other  \n \n';

Link to comment
Share on other sites

Whoops, I also just noticed:

 

It should be:

 

$msg = "FROM: $name \n \n";
  $msg .= "ISSUE, COMMENT OR CONCERN: $other  \n \n";

If you're including the variable in the string you should use double quotes.

Link to comment
Share on other sites

It doesn't appear that the mail is being sent. Should i add the below line between lines #26 & #27?

 

mail($to, $subject, $msg, 'From:' . $email);

 

#26:   $msg .= (empty($name_char)) ? "" : "CHARACTER(S): $name_char  \n \n";
#27:

 

thus producing the following:

#26:   $msg .= (empty($name_char)) ? "" : "CHARACTER(S): $name_char  \n \n";
#27:   mail($to, $subject, $msg, 'From:' . $email);
#28:

 

 

Link to comment
Share on other sites

Thank you AlexWD, MAQ and ECHOFOOL (people thanked in order of having joined this thread).

 

You're all wonderful, I thank you from the bottom of my heart and I look forwards to when I will be able to pay your help forward or if you come to Seattle and swing by the php User Group, I'll happily buy you a cup of coffee or a beer depending on where we're meeting (hopefully it's a place that servers beer cause coffee in Seattle is obscenely expensive ;) )

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.