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.

What's wrong with this syntax?

Discussion in 'PHP' started by lost, Nov 15, 2005.

  1. #1
    Can someone tell me what is wrong with the following syntax:
    
         if ($_SESSION['genericNewConfig'])
         { 
            echo '<INPUT TYPE=submit VALUE="Save"    NAME="generic_savebutton"   ONCLICK="verifySave()" />';
            echo '<INPUT TYPE=reset  VALUE="Cancel"  NAME="generic_cancelbutton" ONCLICK="verifyCancel()" />';
         }
    
    
    PHP:
    I keep getting Error: syntax error
     
    lost, Nov 15, 2005 IP
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    Syntax error in what line?
     
    digitalpoint, Nov 15, 2005 IP
  3. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    in both the lines that start with echo
     
    lost, Nov 15, 2005 IP
  4. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #4
    Nothing wrong with it... I even copy/pasted the code into a new PHP file to make sure and it didn't give any errors.
     
    digitalpoint, Nov 15, 2005 IP
  5. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Okay it must be something else i'm doing, here's the long story....

    I have this method that gets executed first thing called init(), which works fine at first:

    
    <?php
      function init()
      {     
         if ($_SESSION['genericNewConfig'])
         { 
            echo '<INPUT TYPE=submit VALUE="Save"    NAME="generic_savebutton"   ONCLICK="verifySave()" />';
            echo '<INPUT TYPE=reset  VALUE="Cancel"  NAME="generic_cancelbutton" ONCLICK="verifyCancel()" />';
         }
         else 
         {
            echo '<INPUT TYPE=button VALUE="Save"   NAME="generic_savebutton"   DISABLED="disabled" />';  
            echo '<INPUT TYPE=button VALUE="Cancel" NAME="generic_cancelbutton" DISABLED="disabled" />';
         }
      }
    ?>
    
    PHP:

    later on in my code i have a javascript method called createNewConfig() which gets called when i hit "New Config" button, which at the end of it calls the init method to check the status of the SESSION variable.
    However, once it hits the first line in the init() function it gives me a syntax error.

    
    <HTML>
    <HEAD>
    <SCRIPT LANGUAGE="Javascript" TYPE="text/javascript">
      function createNewConfig()
      {      
         //window.location='systemconfig-generic.php';    
         document.getElementById('systemselect').style.display='none';
         document.getElementById('systemselect').value="";
         
         document.getElementById('systemtext').style.display='';
         document.getElementById('systemtext').focus();     
         
         <?php $_SESSION['genericNewConfig'] = true; ?>
         <?php init()?>
      }
    </SCRIPT>
    </HEAD>
    </HTML>  
    
    HTML:
     
    lost, Nov 15, 2005 IP
  6. garysims

    garysims Well-Known Member

    Messages:
    287
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    108
    #6
    This maybe a silly comment as I have never tried what you are doing but can one mix javascript and PHP like that?
     
    garysims, Nov 15, 2005 IP
  7. hnn

    hnn Peon

    Messages:
    91
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You can mix PHP and Javascript like that....
     
    hnn, Nov 15, 2005 IP
  8. torunforever

    torunforever Peon

    Messages:
    414
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Try adding a semicolon on this line.

    <?php init(); ?>
     
    torunforever, Nov 15, 2005 IP
  9. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    didn't work :(
     
    lost, Nov 16, 2005 IP
  10. Mat

    Mat Peon

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Try cutting and pasting the exact error string into here.
     
    Mat, Nov 16, 2005 IP
  11. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Just to let you know, I'm using Mozilla Firefox's JavaScript Console and it keeps outputting this:


    Error: syntax error
    Source File: http://localhost/systemconfig-generic.php
    Line: 132, Column: 10
    Source Code:
    <INPUT TYPE=submit VALUE="Save" NAME="generic_savebutton" ONCLICK="verifySave()" /><INPUT TYPE=reset VALUE="Cancel" NAME="generic_cancelbutton" ONCLICK="verifyCancel()" /> }
     
    lost, Nov 16, 2005 IP
  12. Mat

    Mat Peon

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Thats a javascript (client-side) error, not a php (server-side) error.

    You need to look at line 132 of the html output, not the php code. Do a "view source" and look at line 132.

    Mat
     
    Mat, Nov 16, 2005 IP
  13. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Thats what I've been doing...that line that i originally submitted is line 132 of the HTML output...
     
    lost, Nov 16, 2005 IP
  14. torunforever

    torunforever Peon

    Messages:
    414
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #14
    I just looked at your code again, and while you can "mix PHP and Javascript like that", you can't put HTML in JavaScript. Put your PHP call to init() in the body of your document, and outside any script tags.
     
    torunforever, Nov 16, 2005 IP
  15. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Thanks.
    I understand what you mean, however, i'm not sure i know where exactly to place the init() call. Would i be able to perhaps have 2 method calls for the onclick event, so that they get called one after the other??

    <INPUT TYPE=button VALUE="Create New Configuration" NAME="newconfigbutton" ONCLICK="createNewConfig()" ONCLICK="init()">
     
    lost, Nov 16, 2005 IP
  16. torunforever

    torunforever Peon

    Messages:
    414
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #16
    I'm not sure why you need to split it up?

    Move the php code to be like:

    
    </HEAD>
    <body>
    <?php $_SESSION['genericNewConfig'] = true; ?>
    <?php init(); ?>
    </body>
    </HTML> 
    
    Code (markup):
     
    torunforever, Nov 16, 2005 IP
  17. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #17
    i'm getting syntax errors with that now????
     
    lost, Nov 16, 2005 IP
  18. torunforever

    torunforever Peon

    Messages:
    414
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #18
    The code you posted earlier doesn't look like a complete page. Is there more to the page that you're not showing?

    What errors are you getting now.

    My first suggestion, not knowing the error, would be to put <form> tags around the <input> tags generated by your PHP.
     
    torunforever, Nov 16, 2005 IP
  19. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #19
    
    <FORM ID="genericform" ACTION="systemconfig-generic.php" METHOD="post">
    
      <?php
        init();
      ?>
    
      <CENTER><INPUT TYPE=button VALUE="Create New Configuration" NAME="newconfigbutton" button.ONCLICK="createNewConfig()">
     
    <?php
      function init()
      {     
         if ($_SESSION['genericNewConfig'])
         { 
            echo '<INPUT TYPE=submit VALUE="Save"    NAME="generic_savebutton"   ONCLICK="verifySave()" />';
            echo '<INPUT TYPE=reset  VALUE="Cancel"  NAME="generic_cancelbutton" ONCLICK="verifyCancel()" />';
         }
         else 
         {
            echo '<INPUT TYPE=button VALUE="Save"   NAME="generic_savebutton"   DISABLED="disabled" />';  
            echo '<INPUT TYPE=button VALUE="Cancel" NAME="generic_cancelbutton" DISABLED="disabled" />';
         }
      }
    ?>
    
    </FORM>
    </BODY>	  
    
    <HTML>
    <HEAD>
    <SCRIPT LANGUAGE="Javascript" TYPE="text/javascript">
    
      function createNewConfig()
      {      
         //window.location='systemconfig-generic.php';    
         document.getElementById('systemselect').style.display='none';
         document.getElementById('systemselect').value="";
         
         document.getElementById('systemtext').style.display='';
         document.getElementById('systemtext').focus();
         <HEAD>
         <BODY>
         <?php $_SESSION['genericNewConfig'] = true; ?>     
         <?php init(); ?>
         </BODY>
         </HTML>
      }
    
      function verifySave()
      {
         msg = "Are you sure you want to save this data?";
         //all we have to do is return the return value of the confirm() method
         return confirm(msg);
      }
    
      function verifyCancel()
      {
         msg = "Are you sure you want to cancel?";
         //all we have to do is return the return value of the confirm() method
         return confirm(msg);
      }
     
    </SCRIPT>
    </HEAD>
    </HTML>
    
    
    
    Code (markup):
     
    lost, Nov 16, 2005 IP
  20. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #20
    I'm getting syntax errors that point right at the <HEAD> tag in this chunk of code:
    <HEAD>
    <BODY>
    <?php $_SESSION['genericNewConfig'] = true; ?>
    <?php init(); ?>
    </BODY>
    </HTML>
     
    lost, Nov 16, 2005 IP