Connect with Expertise | Find Experts, Get Answers, Share Insights

Parse error: syntax error, unexpected T_STRING

 
Join Date: Feb 2010
Posts: 4
#1: Feb 9 '10
Hi,

Just found this forum and it looks like a wealth of info!

I'm not a coder and have a problem with the following brief bit of code (reportedly on line 22):

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $d = $_GET["d"];
  3. $m = $_GET["m"];
  4. $y = $_GET["y"];
  5.  
  6. $d = (int) $d;
  7. $m = (int) $m;
  8. $y = (int) $y;
  9.  
  10. $curr = time();
  11.  
  12. $olddt = mktime(0,0,0,$m,$d,$y);
  13.  
  14. $ddiff = $curr - $olddt;
  15. $fulldays = floor($ddiff/(60*60*24));
  16.  
  17. if ($fulldays < 2) { // Change 3 to however many days you want the link to last
  18.     $bannerAd[1] = 'http://www.mysite.com’;
  19.  
  20.     $adCount = count($bannerAd);
  21.     $randomAdNumber = mt_rand(1, $adCount);
  22.         header('Location: ' . $bannerAd[$randomAdNumber]);
  23. }
  24. else {
  25.     header('Location:http://www.mysite2.com/');
  26. }
  27. ?>
I cannot find the problem. If anyone can help it would be super appreciated.

Thanks

Ruchka

Dormilich's Avatar
E
M
C
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 5,372
#2: Feb 9 '10

re: Parse error: syntax error, unexpected T_STRING


is $bannerAd defined anywhere?
 
Join Date: Feb 2010
Posts: 4
#3: Feb 9 '10

re: Parse error: syntax error, unexpected T_STRING


Thanks for responding Dormilich.

The entire code is pasted above. I have no other codes or definitions anywhere else.

As far as I know it could be defined in line 18:

$bannerAd[1] = 'http://www.mysite.com’;

But that is just a guess.
Dormilich's Avatar
E
M
C
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 5,372
#4: Feb 9 '10

re: Parse error: syntax error, unexpected T_STRING


line #18, the string is not closed (a right single quotation mark is different from an apostrophe). therefore the first ' on line 22 is closing the string and PHP expects a . or ; after that.
 
Join Date: Feb 2010
Posts: 4
#5: Feb 9 '10

re: Parse error: syntax error, unexpected T_STRING


Wow OK I see that and I made the change to line #18:

now it is $bannerAd[1] = 'http://www.mysite.com';

but I am still getting the same error. Weird...
Dormilich's Avatar
E
M
C
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 5,372
#6: Feb 9 '10

re: Parse error: syntax error, unexpected T_STRING


well, I can’t see any syntax errors. then you can only comment out lines, maybe you find something this way.
 
Join Date: Feb 2010
Posts: 4
#7: Feb 9 '10

re: Parse error: syntax error, unexpected T_STRING


you mean put

//

before code lines and see what happens?

I will try that. Thanks for you time and help, its much appreciated!
Markus's Avatar
E
C
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 5,533
#8: Feb 9 '10

re: Parse error: syntax error, unexpected T_STRING


Post the revised code along with the full error string.
Reply

Tags
parse error, php, unexpected t string