473,545 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

kestrel
1,071 Recognized Expert Top Contributor
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 22134
skippychalmers
3 New Member
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
skippychalmers
3 New Member
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 Recognized Expert Expert
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 Recognized Expert Top Contributor
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
2875
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 process_card($card_details) { // connect to payment gateway or // use gpg to encrypt and mail or // store in DB if you really want to
5
13140
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') VALUES ('$_POST', '$_POST', '$_POST') mysql_query($sql)"; When I view the code in Internet Explorer I get the following error message: ...
36
7971
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 shortcomings will soon become apparent. I am developing an estimating construction system, using PHP5 and MySQL 5.0.24a with Ubuntu. I have a main...
3
2387
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 help?
2
3210
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", $formName); // 06-22-07 - the next commands try to import all the functions that the
2
3228
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 T_VARIABLE or T_NUM_STRING in /var/www/html/inventoryControl/supplier.php on line 26 (line number changed to match code tags) The code is as follows: ...
3
5589
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 what's the actual problem here..? my code
10
5633
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 $subject_set = get_all_subjects(); while ($subject = mysql_fetch_array($subject_set)) { echo...
14
5489
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 all the rows which have the corresponding state. I am getting this 'Parse error: syntax error, unexpected T_STRING in /home/attorney/public_html/' on...
0
7487
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7934
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7446
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7778
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5349
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4966
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3459
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1908
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
731
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.