Parse syntax error; quotation marks in echo statements

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Parse syntax error; quotation marks in echo statements

Postby 8peoneeslv » 12. March 2020 18:02

Hi folks, any help is greatly appreciated - using version 7.1.30 . I get error messages re the quotation marks used in echo statements; it appears that only single quotation marks can be compiled, as I get messages when I use double q-marks. -- According to php rules for echo statements, one uses double marks to allow values for variables to be inserted, and single marks for exact text. -- Is this error message a "quirk" with this version of xampp? Or am I not coding correctly? The following is a good example of results from xampp...this line: -- echo 'checked="checked" '; -- NOR this line: -- echo "checked='checked' "; -- (ie, switching single and double q-marks; to re-check a "checked" box) compiles in xampp, and both result in the parse error message. --- Please Help, as this is code for my website which I wish to launch soon(?) - how do the browsers handle quotation marks??? --- Thank you!
8peoneeslv
 
Posts: 6
Joined: 12. March 2020 17:08
XAMPP version: 7.4.3
Operating System: win7

Re: Parse syntax error; quotation marks in echo statements

Postby Altrea » 13. March 2020 07:05

Most likely you are using a wrong character set in your coding editor.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 10266
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Parse syntax error; quotation marks in echo statements

Postby 8peoneeslv » 13. March 2020 11:56

Thanks for your very speedy reply...But, what do you mean, "character set"? (btw, I'm using notepad, basic) And, can you/php expert pls confirm: use double q-marks for values for variables, single for exact text? Any confirmation that the browsers, do in fact, interpret (ie, compile) this rule in this way? --- THANKS very much for your patience, and assistance (truly! am tearing my hair out; working on large file that won't compile, due to this problem?)
8peoneeslv
 
Posts: 6
Joined: 12. March 2020 17:08
XAMPP version: 7.4.3
Operating System: win7

Re: Parse syntax error; quotation marks in echo statements

Postby Altrea » 13. March 2020 12:10

8peoneeslv wrote:Thanks for your very speedy reply...But, what do you mean, "character set"?

Ask google about character sets/encoding. A Computer has different ways to save and read a character.
I have written a Q&A about encoding issues in the past, but i am not sure if that will help you at this point https://community.apachefriends.org/f/viewtopic.php?f=16&t=72520#p233795

8peoneeslv wrote:(btw, I'm using notepad, basic)

I would recommend to use a true code editor like Notepad++

8peoneeslv wrote:And, can you/php expert pls confirm: use double q-marks for values for variables, single for exact text?

Use double quotes only if you want to auto expand variables or for better readability in combination with content that require quotes too, like processing html tags or javascript.

8peoneeslv wrote:Any confirmation that the browsers, do in fact, interpret (ie, compile) this rule in this way?

Browsers are not involved at this point the error occurs. Your browser will only get the plain html back from the php interpreter.

btw: where does your code come from? is that written by yourself or copied from somewhere else?
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 10266
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Parse syntax error; quotation marks in echo statements

Postby Nobbie » 13. March 2020 12:34

8peoneeslv wrote:The following is a good example of results from xampp...this line: -- echo 'checked="checked" '; -- NOR this line: -- echo "checked='checked' ";


Please create an example test.php script with the code which does not run, then copy&paste the full script here into this forum, using code tags (see above, there is a "code" button, use that for your code). DO NOT ENTER MANUALLY YOUR CODE WITH THE KEYBOARD. You MUST copy and paste it here.
Nobbie
 
Posts: 11613
Joined: 09. March 2008 13:04

Re: Parse syntax error; quotation marks in echo statements

Postby 8peoneeslv » 13. March 2020 17:36

Code: Select all
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
    .spaces10 {margin-right:10px;}
</style>
</head>
<body>
 <?php
            {echo
                       "<p>Last Name <span class="spaces10"></span>
                                  <input type="text" name="Blast" maxlength="25" size="25"
                                          value="<?php if ($Blast_valid==1)
                                                                 {echo htmlspecialchars (['Blast'], ENT_QUOTES);}
                                                             else 
                                                                 {$Blast = " ";
                                                                   echo 'placeholder="Letters ONLY" ';}
                                                      ?>"
                                     />
                          </p>";
               }
  ?>
</body>
</html>
8peoneeslv
 
Posts: 6
Joined: 12. March 2020 17:08
XAMPP version: 7.4.3
Operating System: win7

Re: Parse syntax error; quotation marks in echo statements

Postby 8peoneeslv » 13. March 2020 17:55

Hi, KIND responders...
In reply to "N": I hope I submitted a snippet code correctly, as requested; it's a snippet of one of my large files. The error msg is as follows: "Parse error: syntax error, unexpected "spaces10" (T_STRING), expecting ',' or ';' ...". This is a typical portion of code, in my files, of which seems to always result in that error msg. In some cases, when I really wished to use " " (double q-marks) bc I wanted values of variables displayed (in echo statements, like in snippet), I replaced them with ' ' (single marks; just to "make it past the compiler"), and then that module was then compiled successfully.
In reply to "A": This is all my code, written by myself (alas, bugs and all). I will consider your suggestion re notepad++ .
To both, kind SIRS: As you can see, code is pretty simple; css, html, and a bit of php...nothing complex. Again, infinite THX for your assistance!
8peoneeslv
 
Posts: 6
Joined: 12. March 2020 17:08
XAMPP version: 7.4.3
Operating System: win7

Re: Parse syntax error; quotation marks in echo statements

Postby Nobbie » 13. March 2020 18:34

Ok, things are clearing up.

Sorry, but your code is total trash. You are using stacked double quotes overall and everywhere:

Code: Select all
<?php
            {echo
                       "<p>Last Name <span class="spaces10"></span>


You have double quotes in the last line above like "<p>Last Name ... and so, and then you have class="spaces10", double quotes inside double quotes. And thats going on in every line, its total trash, really. And then you have stacked php commands, in the weird value clause:

Code: Select all
value="<?php if ($Blast_valid==1)


You are inside a php script and have again a php script. You urgently should redesign your code, thats unreadable and full of errors, stacked double quotes and quotes and errors over errors - there is lot to do to get this error free!
Last edited by Nobbie on 13. March 2020 19:19, edited 1 time in total.
Nobbie
 
Posts: 11613
Joined: 09. March 2008 13:04

Re: Parse syntax error; quotation marks in echo statements

Postby Altrea » 13. March 2020 18:42

Using a code editor with code highlighting is essential for you to see the context changes your code is doing.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 10266
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Parse syntax error; quotation marks in echo statements

Postby 8peoneeslv » 13. March 2020 19:38

Hi again to both of you: Don't know if my last reply was posted...
"N" : Thanks for your honesty; Apparently I don't know how to create ONE line in a form, without the trashy complexity! I'd learned most from StackOverflow, and so I thought my coding was acceptable. Would you care to "dash off" a snippet that achieves at least a portion of this objective, without these horrendous errors?
"A": Apparently I should find another editor :) !
--- To reiterate, to both KIND SIRS: THANK YOU for your patience and assistance!
8peoneeslv
 
Posts: 6
Joined: 12. March 2020 17:08
XAMPP version: 7.4.3
Operating System: win7

Re: Parse syntax error; quotation marks in echo statements

Postby 8peoneeslv » 13. March 2020 20:59

Latest comments: THANKS for your patience and kindness! Working on all your suggestions; esp rewriting code re "N's" very "helpful" comments.
Have a great day/evening :)
8peoneeslv
 
Posts: 6
Joined: 12. March 2020 17:08
XAMPP version: 7.4.3
Operating System: win7

Re: Parse syntax error; quotation marks in echo statements

Postby Nobbie » 13. March 2020 21:16

I dont understand all of the code, there are so many errors, undefined variables, wrong syntax, syntax errors etc.. There is no FORM Tag for a form, only an input field, but i have redesigned as good as i can. Thats the way i would do it:

Code: Select all
<?php
        if 
($Blast_valid == 1)
                $value = htmlspecialchars('Blast', ENT_QUOTES);
        else
                $value 
= 'placeholder="Letters ONLY" ';
?>
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
    .spaces10 {margin-right:10px;}
</style>
</head>
<body>
<p>
<span class="spaces102">Last Name</span><input type="text" name="Blast" maxlength="25" size="25" value='<?=$value?>'>
</p>
</body>
</html>
Nobbie
 
Posts: 11613
Joined: 09. March 2008 13:04

Re: Parse syntax error; quotation marks in echo statements

Postby Altrea » 14. March 2020 10:43

Nobbies code is a good example for a best practice:
Try to separate your php code as much as possible from your html/css/other code.
At the end your html should only contain some additional placeholders to output some preprocessed values.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 10266
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Parse syntax error; quotation marks in echo statements

Postby Nobbie » 14. March 2020 12:57

In some cases, when there is quite a lot of HTML Output, i also put that into an external file and include it in the end of the PHP Script. That enables an HTML Code Editor to edit the output file simply:

Code: Select all
<?php
        if ($Blast_valid == 1)
                $value = htmlspecialchars('Blast', ENT_QUOTES);
        else
                $value = 'placeholder="Letters ONLY" ';

        include "output.html.php";
?>


And output.html.php:

Code: Select all
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
    .spaces10 {margin-right:10px;}
</style>
</head>
<body>
<p>
<span class="spaces102">Last Name</span><input type="text" name="Blast" maxlength="25" size="25" value='<?=$value?>'>
</p>
</body>
</html>


That is the way i usually code all my scripts. At first the functional part in PHP, fill variables to your needs, finally include the output html code. The HTML Code can be processed with any WYSIWYG Editor.
Nobbie
 
Posts: 11613
Joined: 09. March 2008 13:04


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 94 guests