0

I have a little strange issue with my php 7.4... I imported a website from another place on a new ubuntu server. In this wordpress website I have a plugin where I have a php file containing this function (there are omissions because they are private):

function insert_registration() 
{
    
    if ( $this->validate_state === FALSE ) 
    {
    
        echo $this->validate_state;
        $this->title_message = __('XXXXXXXXXXXX!', 'XXXXXXX');
        $this->error_message = __('XXXXXXXXXXXXXXXXXXXXXX', 'XXXXXXXXXX') . ' ';
        $this->error_message .= $this->error_reason;
        ?>
            <script type="text/javascript">new $.Zebra_Dialog('<?php echo $this->error_message; ?>', { 'custom_class': 'XXXXXXXX', 'title' : '<?php echo $this->title_message; ?>' });</script>
        <?php
        
        
    } 
    else  // <-------- the ELSE where the error is complaining about
    {
    
        $asd = $this->wpdb->insert(
            'XXXXXXX',
            array(
                'XXXXXXX' => $this->var1,
                'XXXXXXX' => $this->var2,
                'XXXXXXX' => $this->var3,
                'XXXXXXX' => $this->var4,
                'XXXXXXX' => (!$this->var5 ? '': $this->var5),
                'XXXXXXX' => MD5($this->var6),
                'XXXXXXX' => current_time('mysql', 1)
            ),
            array('%s', '%s', '%s', '%s', '%s', '%s', '%s')
        );
        
        $asd2 = $this->wpdb->insert_id;             
        
        if ( $asd == 1 ) 
        {
            
            if ( isset($this->var7) ) 
            {
                $varvar7 = $this->wpdb->get_var('SELECT XXXXXXXXX FROM XXXXXXXX WHERE XXXXXXXX = "' . $this->var7 . '" ' );
            }

            $new_var7 = $this->wpdb->get_var('SELECT CAST(LPAD(IFNULL(MAX(CAST(XXXXXXXXXXX AS UNSIGNED)), 000000)+1, 6, "0") AS CHAR(6)) AS "col1" FROM XXXXXXXXXXXXX');
            
            $new_var = $this->wpdb->insert(
                'XXXXXXXX',
                array(
                    'XXXXXX' => $this->var1, 
                    'XXXXXX' => $this->var8,
                    'XXXXXX' => $this->var9,
                    'XXXXXX' => $new_var7,
                    'XXXXXX' => $asd,
                    'XXXXXX' => $new_var7,
                    'XXXXXX' =>  $this->var10,
                    'XXXXXX' => 1
                ),
                array('%s', '%s', '%s', '%d', '%d', '%s', '%s', '%d')
            );

            $var7 = $this->wpdb->insert(
                    'XXXXXXXXX',
                    array(
                        'XXXXXXXXX' => $new_var7
                    ),
                    array('%d')
            );


            if ( !($new_var7 == 1) ) 
            {
                
                $this->var9 = __('XXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXXx');
                $this->var10 = __('XXXXXXXXXXXXXXXXXXxx', 'XXXXXXXXXXXXXXXXXx');
                ?>
                    <script type="text/javascript">new $.Zebra_Dialog("<?php echo $this->var9; ?>", { "custom_class": "xxxxxxxxxx", "title" : "<?php echo $this->var10; ?>"});</script>
                <?php   
                
                
            } else {                
                                        
                // message user udpated
                $this->var9 = __('XXXXXXXXXXXXXXXXXXXXXx', 'XXXXXXXXXXXXXXXX');
                $this->var10 = __('XXXXXXXXXXXXXXXXXXXXX','XXXXXXXXXXXXXXXXX');
                $session_lang = pll_current_language();
                $browser_lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
                $this->url_redirect = "XXX.XXX.XXX.XXX";
                if ($session_lang != $browser_lang) 
                {
                    $this->url_redirect .= $session_lang . "/";
                }
                
                
                ?>
                    <script type="text/javascript">new $.Zebra_Dialog('<?php echo $this->var9; ?>', { 'custom_class': 'XXXXXXXXXXXXXx', 'title' : '<?php echo $this->var10; ?>', 'onClose' : function(caption) { window.location='<?php echo $this->url_redirect; ?>'; } }); </script>
                <?php
                
                $message_html_template =  '<h1 style="font-family: Calibri"><center>XXXXXXXXXXXXXXXXXX</center><h1>&nbsp;<hr>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX') . '</p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXXXXXX ', 'XXXXXXXXXXXXXXX') . $new_var7 . '</p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXXXX: ', 'XXXXXXXXXXXXXx') . $this->asd1 . ' - ' . $this->asd2 . '</p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXXXXX: ', 'XXXXXXXXXXXXX') . $this->asd3 . '</p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXx ', 'XXXXXXXXXXX') . $this->asd4 . '</p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXXxx: ', 'XXXXXXXXXXXXXX') . $this->asd5 . '</p></div>';
                $message_html_template .= '<hr><div style="font-family: Calibri; font-size: 0.6em"><p><center>XXXXXXXXXXXXXXX</center></p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p><center>XXXXXXXXXXXXXXXXXXXXX</center></p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p><center>XXXXXXXXXXXXXXXXXX</center></p></div>';
                                        
                $to = $this->to;
                $subject = __('XXXXXXXXXXXXXx', 'XXXXXXXXXXXxxx');
                $message = $message_html_template;
                $headers = 'From: XXXXXXXXXXXXX <XXXXXXXXXXXXXX>' . "\r\n";
                
                add_filter('wp_mail_content_type', function( $content_type ) { return 'text/html'; });
                wp_mail( $to, $subject, $message, $headers );
                
                $message_html_template =  '<h1 style="font-family: Calibri"><center>XXXXXXXXXXXXXXXXXX</center><h1>&nbsp;<hr>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX') . '</p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXXXXXX ', 'XXXXXXXXXXXXXXX') . $new_var7 . '</p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXXXX: ', 'XXXXXXXXXXXXXx') . $this->asd1 . ' - ' . $this->asd2 . '</p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXXXXX: ', 'XXXXXXXXXXXXX') . $this->asd3 . '</p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXx ', 'XXXXXXXXXXX') . $this->asd4 . '</p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXXxx: ', 'XXXXXXXXXXXXXX') . $this->asd5 . '</p></div>';
                $message_html_template .= '<hr><div style="font-family: Calibri; font-size: 0.6em"><p><center>XXXXXXXXXXXXXXX</center></p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p><center>XXXXXXXXXXXXXXXXXXXXX</center></p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p><center>XXXXXXXXXXXXXXXXXX</center></p></div>';
                
                $to = get_bloginfo('admin_email');
                $subject = 'XXXXXXXXXXXXXXXXXXXX';
                $message = $message_html_template;
                $headers = 'From: XXXXXXXXXX <XXXXXXXXXX>' . "\r\n";
                
                add_filter('wp_mail_content_type', function( $content_type ) { return 'text/html'; });                          
                wp_mail( $to, $subject, $message, $headers );
                                        
            }
            
        } else {
            ?>
                <script type="text/javascript">new $.Zebra_Dialog('<?php echo $new_var->get_error_message(); ?>');</script>
            <?php                   
        }
    
    }
}

I checked all the indentations of the whole PHP file and they looks correct but the website goes down with an error and reading the error.log file I see :

[Tue May 03 11:08:11.334843 2022] [php7:error] [pid 3075] [client XXX.XXX.XXX.XXX:59496] PHP Parse error: syntax error, unexpected 'else' (T_ELSE), expecting function (T_FUNCTION) or const (T_CONST) in

but as I said before all indentations are correct... could be maybe related to the presence of mixed HTML and PHP code? like in the else:

... else { ?> <script type="text/javascript">new $.Zebra_Dialog('<?php echo $new_var->get_error_message(); ?>');</script> <?php }

where maybe php doesn't like it? In the previous server it didn't give any errors,... maybe some php.ini misconfiguration?

thanks in advance to all! Cheers!!

EDIT: Removed all code then re-added step-by-step , I figured this piece of code:

function registration_template_form() 
{

    $this->var1 = __('XXXX', 'XXXX');
    $this->var2 = __('XXXXX', 'XXXXXX');
    $this->var3 = __('XXXXX', 'XXXXX');
    
    ?>  
    <script type="text/javascript">             
    </script>           
    <div class="popup_canvas_container">
    </div>
    <?
    
}

breaks the website and throwns the error even if different message than earlier but so it looks like it is related about mixing html with php; in fact removing the html part in the function then it works.

Luigino
  • 745
  • 3
  • 7
  • 26
  • Which of the `else`s in your code is it complaining about? Mixing HTML and PHP won't cause a problem specifically. More likely you're just missing a bracket or semicolon somewhere. – ADyson May 03 '22 at 10:27
  • Actually this code doesn't appear to contain any syntax errors - https://3v4l.org/9s7Ou . Maybe the problem is elsewhere, you didn't tell us specifically what line the error message refers to. – ADyson May 03 '22 at 10:34
  • Hello @ADyson , first thank you for the answer. I just re-edited the code to point at the else who is complaining error about. But as you confirmed me, mixing html and php wouldn't cause a problem and weird thing is in the other server where I imported from the whole website doesn't complain any php error like this making the website breaking down.... even I checked in the whole PHP file if there could be someother problem but it looks like well formed.... that's why I was asking for. – Luigino May 03 '22 at 10:53
  • If the scripts starts with this function, then you should put a php opening tag at the top of the page ` – Onki Hara May 03 '22 at 11:22
  • Thanks for the update. It must be related to something in the nearby context then, which is throwing it off balance. Some little difference - some missing code or bracket, or some issue in a file which this file `include`s, or whatever. Unfortunately we can't tell just from what you've posted - as I showed, this content by itself is ok. The guide in the duplicate question gives some techniques for trying to trace these types of issues. – ADyson May 03 '22 at 11:25
  • hello @ADyson , I removed the whole code and re-added step-by-step and I figured , as you can look at the question post I re-edited adding the code that throwns error, it looks like related to some mixing HTML and PHP even if it shouldn't.... maybe it's related to some PHP misconfiguration about mixing HTML and PHP?... – Luigino May 03 '22 at 12:41
  • Ah... `` needs to be ` – ADyson May 03 '22 at 12:51
  • Thanks @ADyson , I knew it could be possible to use also short tags just like to start/restart php section... so I modified that to – Luigino May 03 '22 at 13:28
  • yes, whether these short tags are allowed is controlled by a PHP setting. Normally it's switched off in modern installations of PHP. Even if you can't reach the ini file you should be able to run `phpinfo();` in a script to see all the settings. No problem anyway, glad I could help – ADyson May 03 '22 at 15:12

0 Answers0