Results 1 to 9 of 9

Thread: Parse Error

  1. #1
    Join Date
    Apr 2012
    Location
    Central New Jersey
    Posts
    295
    Thanks
    104
    Thanked 3 Times in 3 Posts

    Default Parse Error

    G'day Folks,

    This
    Code:
    <?php
    if ($here !== 'quotations') {
    	echo '<body class = "' . $here . '">';
    }
    else {
    	echo '<body class = "quotations" onbeforeunload = "alert('Thanks for visiting. Sorry you couldn't stay longer. We hope you return soon. And tell your friends!')">';
    }
    ?>
    Results in this:

    Parse error: syntax error, unexpected 'Thanks' (T_STRING), expecting ';' or ',' in /home/marainla/public_html/includes/top.inc.php on line 594

    Seeking fresh eyes.

    A.

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,429
    Thanks
    105
    Thanked 117 Times in 115 Posts

    Default

    Let me know if this works.

    I notice you have a bit of what appears to be javascript mixed in there of which I have virtually zero knowledge of, so I may have escaped too many quotes.

    Code:
    <?php
    $here='quotations';
    if ($here !== 'quotations') {
    	echo "<body class = \"' . $here . '\">";
    }
    else {
    	echo "<body class = \"quotations\" onbeforeunload = \"alert(\'Thanks for visiting. Sorry you couldn\'t stay longer. We hope you return soon. And tell your friends!\')\">";
    }
    ?>
    To choose the lesser of two evils is still to choose evil. My personal site

  3. The Following User Says Thank You to james438 For This Useful Post:

    marain (01-25-2022)

  4. #3
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    2,259
    Thanks
    3
    Thanked 283 Times in 276 Posts

    Default

    Hi there marain,

    As James has pointed out, it appears that you have an escaping
    apostrophes problem.

    Try it like this...
    PHP Code:
    <?php

     $here 
    'codetest';

    if ( 
    $here !== 'quotations' ) {
      echo 
    '<body class="'$here .'">';
     }
    else {
    echo 
    '<body class="quotations" onbeforeunload="alert(\'Thanks for visiting. Sorry you couldn\'t stay longer. We hope you return soon. And tell your friends!\')">';
     }
    ?>
    From the little I know about javascript, I think that you are going to
    have the biggest problem with onbeforeunload implementation.

    And it certainly should not be in the body tag. If it has any possible
    chance of working it will need to be coded in the script element.

    coothead
    Last edited by coothead; 01-25-2022 at 06:57 PM.
    ~ the original bald headed old fart ~

  5. The Following 2 Users Say Thank You to coothead For This Useful Post:

    james438 (01-24-2022),marain (01-25-2022)

  6. #4
    Join Date
    Apr 2012
    Location
    Central New Jersey
    Posts
    295
    Thanks
    104
    Thanked 3 Times in 3 Posts

    Default

    James and Coothead,

    Thank you both.

    My apologies for my delay in responding: I've been tremendously busy at work, and unable to test your proposed solutions.

    On the subject of whether the onbeforeunload should be in the body, I was using as a model https://www.w3schools.com/jsref/even...foreunload.asp.

  7. #5
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    2,259
    Thanks
    3
    Thanked 283 Times in 276 Posts

    Default

    Hi there marain,

    you should not consider w3schools to be a reliable source for good coding advise.

    As for...
    Code:
    <body onbeforeunload="alert('Thanks for visiting...')">
    Further reading:-

    Try this site which has far more reliable information concerning onbeforeunload...

    Personally though, I have not been able to implement it in any of my browsers.

    coothead
    Last edited by coothead; 01-25-2022 at 07:00 PM.
    ~ the original bald headed old fart ~

  8. #6
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    2,259
    Thanks
    3
    Thanked 283 Times in 276 Posts

    Default

    Hi there marain,

    I have now unraveled the mystery that is beforeunload.

    Here is an example page...
    Code:
    <!DOCTYPE HTML>
    <html lang="en">
    <head>
    
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1">
    
    <title>Beforeunload Test</title>
    
    </head>
    <body>
    
     <h1>Beforeunload Test</h1> 
    
     <p>
      Clicking this link will activate the <i>beforeunload</i> event<br>
      in both Firefox and Chrome.
    </p>
            <a href="https://www.example.com/">example.com </a>
     <p>
        Clicking tab close (  X ) or the page refresh tab(  C )  will <br>
         only work if the link has  been <b>previously clicked</b>.
    </p><p>
        Neither browser will accept user text.<br>
        Firefox uses this...
    </p>
    <blockquote>
         <i>"This page is asking you to confirm that you want to<br>
          leave   — information you’ve entered may not be saved."</i>
    </blockquote>
    <p>
        ...while Chrome  uses this...
    </p>
    <blockquote>
         <i>"Changes that you made may not be saved."</i>
    </blockquote>
    
    <script>
       window.addEventListener( 'beforeunload',  function(event)  {
          event.preventDefault();
     /* Google Chrome requires returnValue to be set. */
          event.returnValue = '';
      });
    </script>
    
    </body>
    </html>
    I trust that this will help.

    coothead
    ~ the original bald headed old fart ~

  9. The Following User Says Thank You to coothead For This Useful Post:

    marain (02-18-2022)

  10. #7
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    2,259
    Thanks
    3
    Thanked 283 Times in 276 Posts

    Default


    ...of course, as you can no longer use this...

    "Thanks for visiting. Sorry you couldn't stay longer.
    We hope you return soon. And tell your friends!"
    ...I can see no good reason to aggravate your visitors by
    using the intrusive beforeunload.

    coothead
    ~ the original bald headed old fart ~

  11. The Following User Says Thank You to coothead For This Useful Post:

    marain (02-18-2022)

  12. #8
    Join Date
    Apr 2012
    Location
    Central New Jersey
    Posts
    295
    Thanks
    104
    Thanked 3 Times in 3 Posts

    Default

    Well, I'm having a design problem that I find perplexing. Many people visit the Poker Portal page on www.MarainLaw.com, but nobody, absolutely nobody, exhausts their allotted number of poker hands. I don't know why people leave so early, and would love to find some way to entice visitors to tell me.

    I also see that I never properly thanked you for your response of 1-25-2022. Thank you!

  13. #9
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    2,259
    Thanks
    3
    Thanked 283 Times in 276 Posts

    Default

    Quote Originally Posted by marain
    I don't know why people leave so early, and would love to find some way to entice visitors to tell me.

    I believe, as it appears to be some kind of game, that it should be presented in a
    much less cluttered enviroment.

    Something more on these lines...

    poker portal page image

    Perhaps you should also consider adding a comments option to the page.

    Another possible reason for prople leaving so early may be because, like me,
    they do not fully understand your instructions and/or intentions.

    coothead
    Last edited by coothead; 02-20-2022 at 12:53 PM.
    ~ the original bald headed old fart ~

  14. The Following User Says Thank You to coothead For This Useful Post:

    marain (05-15-2022)

Similar Threads

  1. Resolved Parse error: syntax error unexpected 'echo'
    By Kage Kazumi in forum PHP
    Replies: 3
    Last Post: 10-21-2012, 08:19 PM
  2. Replies: 1
    Last Post: 01-28-2011, 03:39 AM
  3. Parse error: syntax error, unexpected $end
    By heavensgate15 in forum PHP
    Replies: 2
    Last Post: 02-24-2010, 06:38 AM
  4. Replies: 2
    Last Post: 02-12-2010, 09:53 AM
  5. Replies: 1
    Last Post: 04-26-2008, 11:22 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •