473,320 Members | 1,580 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

PHP Parse Error: syntax error, unexpected T_STRING, expecting ',' or ';'

kestrel
1,071 Expert 1GB
I have some html code that is supposed to be displayed by php echo. But for some reason i keep getting a syntax error, and i cant figure out what is going on.

Heres what i have
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(isset($_GET['login'])) { 
  3. echo "<div id="visible">";
  4. echo "<span onclick="swapform()">Log In Form</span>";
  5. echo "</div>";
  6. echo "<div id="theform" style="visibility: hidden">";
  7. echo "<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">";
  8. echo "<input type="text" value="Site Name" /><br />";
  9. echo "<input type="submit" value="rub a dub" />";
  10. echo "</form>";
  11. echo "</div>"; 
  12. }
  13. ?>
  14.  
and my error message is
Expand|Select|Wrap|Line Numbers
  1. Parse error:  syntax error, unexpected T_STRING, expecting ',' or ';' in /www/110mb.com/t/h/e/j/e/t/p/a/thejetpage/htdocs/test/index.php on line 24
Line 24 is line 4 up there.

Is there anything wrong there? or is some code getting mixed up with the php code?

Thanks alot

--
Kestrel
Jun 16 '07 #1
4 22096
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(isset($_GET['login'])) { 
  3. echo "<div id=\"visible\">";
  4. echo "<span onclick=\"swapform()\">Log In Form</span>";
  5. echo "</div>";
  6. echo "<div id=\"theform\" style=\"visibility: hidden\">";
  7. echo "<form action=\"<?php echo $_SERVER['PHP_SELF']; ?>\" method=\"post\">";
  8. echo "<input type=\"text\" value=\"Site Name\" /><br />";
  9. echo "<input type=\"submit\" value=\"rub a dub\" />";
  10. echo "</form>";
  11. echo "</div>"; 
  12. }
  13. ?>
  14.  
The problem here looks like its a double quote conflict. You need to escape the double quotes with a backslash like this \", when they're in the string. The above version of your code should work. However, unless u're evalling this later on.. you'll get a html error when the <?php echo line is read... For that line I'd do this:
Expand|Select|Wrap|Line Numbers
  1. eval ("<form action=\""<?php echo $_SERVER['PHP_SELF']; ?>"\" method=\"post\">");
  2.  
Haven't checked that though, but you get the idea. My recent regex adventures with the e modifier may have confused my general eval syntax a little.

Good luck!
Jun 16 '07 #2
Sorry. Eval code for line 7 of your orignal code should be:
Expand|Select|Wrap|Line Numbers
  1. eval ('?><form action="<?php echo $_SERVER[\'PHP_SELF\']; ?>" method="post">');
  2.  
Use the single quotes to avoid a whitespace and T_ error. Translates the string as being literal. Also, you'll need to comment out the single quotes in that form 'PHP_SELF', so that it reads \'PHP_SELF\'.

I can confirm that the above works...
Jun 16 '07 #3
pbmods
5,821 Expert 4TB
Try this instead:
Expand|Select|Wrap|Line Numbers
  1. "<form action=\"$_SERVER[PHP_SELF]\" method=\"post\">
Or better yet:
Expand|Select|Wrap|Line Numbers
  1. echo <<<EOT
  2. <div id="visible">
  3. <span onclick="swapform()">Log In Form</span>
  4. </div>
  5. <div id="theform" style="visibility: hidden">
  6. <form action="$_SERVER[PHP_SELF]" method="post">
  7. <input type="text" value="Site Name" /><br />
  8. <input type="submit" value="rub a dub" />
  9. </form>
  10. </div>
  11. EOT;
  12.  
http://www.php.net/manual/en/languag...syntax.heredoc

Remember that anything you echo goes straight to the browser, so putting PHP code in an echo statement won't cause it to get executed.
Jun 17 '07 #4
kestrel
1,071 Expert 1GB
Thank you so much. I was ripping my hair out over this problem. I dont do php all that offen, and im about as good at php as Shaq is at free throw shooting. Anyways, thanks for your help guys.

-
Kestrel
Jun 17 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Salim | last post by:
Hi people, keep getting this errorParse error: parse error, unexpected T_STRING in order_fns.php line 91. the code is below for the file and I've indicated line 91 <?php function...
5
by: Anna MZ | last post by:
I am new to php and have written the following mysql code to enter the details of a new user in the admin subdomain of my website: $sql = "INSERT INTO 'users' ('userid', 'username', 'upassword')...
36
by: rhys | last post by:
My Gurus and Angels -- Please pardon this old-school programmer, only recently enlightened to open-source, having been trapped in the convenience of proprietary lingos for way too long. My...
3
by: sclarkstone | last post by:
Im getting this error; Parse error: syntax error, unexpected T_STRING, expecting ':' or ';' with this line; header ('postcodesearch.php?e=nw&pcode=',); I cant find whats wrong, can anyone...
2
by: Lawrence Krubner | last post by:
Imagine a template system that works by getting a file, as a string, and then putting it through eval(), something like this: $formAsString = $controller->command("readFileAndReturnString",...
2
by: fburn | last post by:
I need some help with an error I'm getting using php 5.2.5 running on linux. I receive an error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or...
3
paulrajj
by: paulrajj | last post by:
hi to all, i am getting syntax error on my code.. Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in D:\xampp\htdocs\Dummy\paulraj\matrim\exam.php on line 62 ...
10
by: benicio | last post by:
Parse error: syntax error, unexpected T_STRING, expecting '(' in C:\wamp\www\study_group\includes\functions.php on line 19 I got this error and this syntax is from 8 to 19th line. <?php ...
14
riverdale1567
by: riverdale1567 | last post by:
Hi I am a newbie trying to get some of my first code working, yada yada yada. I have a drop down box which chooses a state then takes the post data to 'processform2.php' to use that to pull up...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.