1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help with a syntax error

Discussion in 'Programming' started by chrisj, Aug 6, 2016.

  1. #1
    I'm getting this error:

    Parse error: syntax error, unexpected '[', expecting ',' or ';' in /home/public_html/uploader.php on line 6

    if(isset($_SESSION['channel_id'])) {
        echo '<input type="hidden" name="channel" value="1" />';
        } else {
        echo '<select class="upload-video-form-input" name="channel" onchange="javascript:ahahscript.ahah('[var.base_url]/uploader.php?sub_cat='+ document.form_upload.channel.value, 'sub_change', '', 'GET', '', this);">
        &nbsp;[var.fields_all;htmlconv=no]</select>';
        }
    Code (markup):
    Can you help me find how/where to correct the error?

    Any help will be appreciated.
     
    chrisj, Aug 6, 2016 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    You're having trouble because of inline-javascript. Which you shouldn't use. But if you do, you will have to decide how you want to escape the single quotes. But the better solution is to just not use inline javascript.
     
    PoPSiCLe, Aug 6, 2016 IP
    sarahk likes this.
  3. WebDeveloperOne

    WebDeveloperOne Peon

    Messages:
    24
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    3
    #3
    Hope i solved this
    if(isset($_SESSION['channel_id'])) {
        echo '<input type="hidden" name="channel" value="1" />';
        } else {
        echo '<select class="upload-video-form-input" name="channel" onchange="javascript:ahahscript.ahah(\'[var.base_url]/uploader.php?sub_cat=\'+ document.form_upload.channel.value, \'sub_change\', \'\', \'GET\', \'\', this);">&nbsp;[var.fields_all;htmlconv=no]</select>';
        }
    PHP:
     
    WebDeveloperOne, Aug 11, 2016 IP
    sarahk likes this.
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #4
    @WebDeveloperOne showed you it right, escape your single quotes inside the strings with leading slashes -- little tip though, if you only have two results and no other code running, don't waste time with an if and two echo to do the job of one echo and a ternary operator. Also with onchange it's automatically javascript, so saying javascript: actually breaks it. That "javascript:" is only used in HREF, not in any of the onevent handlers.

    
    echo isset($_SESSION['channel_id']) ?
    	'<input type="hidden" name="channel" value="1">' :
    	'<select
    		class="upload-video-form-input"
    		name="channel"
    		onchange="ahahscript.ahah(\'[var.base_url]/uploader.php?sub_cat=\'+ document.form_upload.channel.value, \'sub_change\', \'\', \'GET\', \'\', this);">
        &nbsp; [var.fields_all;htmlconv=no]
       </select>';
    
    Code (markup):
    That said...

    *DINGDINGDINGDINGDNIG* we have a winner. If you are using any of the onevent methods in the markup, or using href="javascript:" you have sloppy and possibly insecure scripting... which is why those are blocked from working whatsoever if you use the new "content security policy" from HTML 5. (one of the few things in HTML 5 I like)

    https://www.w3.org/TR/CSP/

    No more onchange, onclick, etc, in the markup... no more <script> tag unless it's loading a script, sandboxing like a sandboxed iframe is to further reduce context bleed...

    People in the know have said for over a decade to stop using those things -- but of course like everything else we've been told not to do on websites since 4 Strict dropped in 1998, people just keep sleazing along doing it.
     
    deathshadow, Aug 12, 2016 IP
    sarahk likes this.