Jump to content

I need halp. Before anybody says it's not right to mix php and html, I already know that. This is just an experiment. Theproblem is whenever I try to load the php page on a web browser, it's not working. I'm getting a blank screen. It's not even printing out: this is a test.

 

Can anybody please tell me what's wrong? I'll give you an imaginary cookie

 

<?php
echo'this is a test';
echo'    <head>';

echo'    <script src="js/jquery/jquery.js"></script>';
echo'    <script src="DataTables/media/js/jquery.dataTables.js" type="text/javascript"></script>';
echo'    <script src="DataTables/extensions/Buttons/js/dataTables.buttons.js" type="text/javascript"></script>';
echo'    <script src="DataTables/extensions/Buttons/js/buttons.flash.js" type="text/javascript"></script>;'
echo'    <script src="DataTables/extensions/Buttons/js/buttons.html5.js" type="text/javascript"></script>';
echo'    <script src="js/jszip.min.js" type="text/javascript"></script>';
echo'    <link  rel="stylesheet" href="css/buttons.dataTables.min.css" type= "text/css">';
echo'    <link  rel="stylesheet" href="css/styling.css" type="text/csst">';
echo'    <link  rel="stylesheet" href="css/jquery.dataTables.min.css" type= "text/css">';


echo'    </head>';

echo'    <body>';
echo'        <table id="demoTable">';
echo'                <thead>';
echo'                        <tr>';
echo'                                <th>Name</th>';
echo'                                <th>Program</th>';
echo'                                <th>Age</th>';
echo'                                <th>Homecity</th>';
echo'                        </tr>';
echo'                </thead>';
echo'                <tbody>';
echo'                        <tr>';
echo'                                <td>A</td>';
echo'                                <td>Computer Engineering</td>';
echo'                                <td>20 Years old</td>';
echo'                                <td>Mississauga</td>';
echo'                        </tr>';
echo'                        <tr>';
echo'                                <td>B</td>';
echo'                                <td>Computer Engineering</td>';
echo'                                <td>19 Years old</td>';
echo'                                <td>Vancouver</td>';
echo'                        </tr>';
echo'                        <tr>';
echo'                                <td>C</td>';
echo'                                <td>Computer Engineering</td>';
echo'                                <td>19 Years old</td>';
echo'                                <td>Vancouver</td>';
echo'                        </tr>';
echo'                        <tr>';
echo'                                <td>D</td>';
echo'                                <td>Computer Engineering</td>';
echo'                                <td>19 years old</td>';
echo'                                <td>Ottawa</td>';
echo'                        </tr>';
echo'                </tbody>';
echo'        </table>';
echo'        <script type="text/javascript">';
echo'           $(function(){';
echo'             $(#"demoTable").DataTable({';
echo'               dom: 'Bfrtip',';
echo'                 buttons: ['csv','excel', 'copy'],';
echo'                   stripeClasses: [ 'odd', 'even']';
echo'                 });';
echo'       })';
echo'</script>';
echo'</body>';
?>                                                                                                                                                                                                         

 

Link to comment
https://linustechtips.com/topic/781131-php-html-halp/
Share on other sites

Link to post
Share on other sites

You should always explain what you did to fix it so if others have this problem they can fix it.

Because you where already using single quotes, and JavaScript was using single quotes, they were interfering so you have to do:

\'

Also one of the semi-colons were in the wrong place.

 

See fixed here:

Spoiler

<?php
echo 'this is a test';
echo'    <head>';

echo'    <script src="js/jquery/jquery.js"></script>';
echo'    <script src="DataTables/media/js/jquery.dataTables.js" type="text/javascript"></script>';
echo'    <script src="DataTables/extensions/Buttons/js/dataTables.buttons.js" type="text/javascript"></script>';
echo'    <script src="DataTables/extensions/Buttons/js/buttons.flash.js" type="text/javascript"></script>';
echo'    <script src="DataTables/extensions/Buttons/js/buttons.html5.js" type="text/javascript"></script>';
echo'    <script src="js/jszip.min.js" type="text/javascript"></script>';
echo'    <link  rel="stylesheet" href="css/buttons.dataTables.min.css" type= "text/css">';
echo'    <link  rel="stylesheet" href="css/styling.css" type="text/csst">';
echo'    <link  rel="stylesheet" href="css/jquery.dataTables.min.css" type= "text/css">';


echo'    </head>';

echo'    <body>';
echo'        <table id="demoTable">';
echo'                <thead>';
echo'                        <tr>';
echo'                                <th>Name</th>';
echo'                                <th>Program</th>';
echo'                                <th>Age</th>';
echo'                                <th>Homecity</th>';
echo'                        </tr>';
echo'                </thead>';
echo'                <tbody>';
echo'                        <tr>';
echo'                                <td>A</td>';
echo'                                <td>Computer Engineering</td>';
echo'                                <td>20 Years old</td>';
echo'                                <td>Mississauga</td>';
echo'                        </tr>';
echo'                        <tr>';
echo'                                <td>B</td>';
echo'                                <td>Computer Engineering</td>';
echo'                                <td>19 Years old</td>';
echo'                                <td>Vancouver</td>';
echo'                        </tr>';
echo'                        <tr>';
echo'                                <td>C</td>';
echo'                                <td>Computer Engineering</td>';
echo'                                <td>19 Years old</td>';
echo'                                <td>Vancouver</td>';
echo'                        </tr>';
echo'                        <tr>';
echo'                                <td>D</td>';
echo'                                <td>Computer Engineering</td>';
echo'                                <td>19 years old</td>';
echo'                                <td>Ottawa</td>';
echo'                        </tr>';
echo'                </tbody>';
echo'        </table>';
echo'        <script type="text/javascript">';
echo'           $(function(){';
echo'             $(#"demoTable").DataTable({';
echo'               dom: \'Bfrtip\',';
echo'                 buttons: [\'csv\',\'excel\', \'copy\'],';
echo'                   stripeClasses: [ \'odd\', \'even\']';
echo'                 });';
echo'       })';
echo'</script>';
echo'</body>';
?>                                                                    

 

 

Link to comment
https://linustechtips.com/topic/781131-php-html-halp/#findComment-9848135
Share on other sites

Link to post
Share on other sites

Yeah,  and you know you can just say something like this :

 

echo 'This is first line
This is the next line 
here\'s more text. ';

and it would work;

 

and you can theoretically also use the HEREDOC syntax :

 

<?php
$text = <<<SOMEKEYWORD
This is first line
This is the next line 
here's more text.                      
SOMEKEYWORD;
echo $text;                      
?>

The text that starts after the line with <<< and keyword up to the line with just the keyword on it is treated as if it's entered between double quotes  ( " " ) but you don't have to escape the " characters  and some escaped combos like \t for tab, \n for newline would be converted to the proper characters.

This style of writing is rarely used, this website's code doesn't even parse it correctly.

 

Link to comment
https://linustechtips.com/topic/781131-php-html-halp/#findComment-9850084
Share on other sites

Link to post
Share on other sites

5 hours ago, Cruorzy said:

Easiest fix would have been to remove the php tag and the echo's just make it "normal" html.

Only open a php tag when its needed like 


<p><?php echo htmlentities($string); ?></p>

 

not only does it look much better but it is a useless waste php processing. 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
https://linustechtips.com/topic/781131-php-html-halp/#findComment-9850649
Share on other sites

Link to post
Share on other sites

14 hours ago, aidanapple said:

You should always explain what you did to fix it so if others have this problem they can fix it.

Because you where already using single quotes, and JavaScript was using single quotes, they were interfering so you have to do:


\'

Also one of the semi-colons were in the wrong place.

 

See fixed here:

  Hide contents


<?php
echo 'this is a test';
echo'    <head>';

echo'    <script src="js/jquery/jquery.js"></script>';
echo'    <script src="DataTables/media/js/jquery.dataTables.js" type="text/javascript"></script>';
echo'    <script src="DataTables/extensions/Buttons/js/dataTables.buttons.js" type="text/javascript"></script>';
echo'    <script src="DataTables/extensions/Buttons/js/buttons.flash.js" type="text/javascript"></script>';
echo'    <script src="DataTables/extensions/Buttons/js/buttons.html5.js" type="text/javascript"></script>';
echo'    <script src="js/jszip.min.js" type="text/javascript"></script>';
echo'    <link  rel="stylesheet" href="css/buttons.dataTables.min.css" type= "text/css">';
echo'    <link  rel="stylesheet" href="css/styling.css" type="text/csst">';
echo'    <link  rel="stylesheet" href="css/jquery.dataTables.min.css" type= "text/css">';


echo'    </head>';

echo'    <body>';
echo'        <table id="demoTable">';
echo'                <thead>';
echo'                        <tr>';
echo'                                <th>Name</th>';
echo'                                <th>Program</th>';
echo'                                <th>Age</th>';
echo'                                <th>Homecity</th>';
echo'                        </tr>';
echo'                </thead>';
echo'                <tbody>';
echo'                        <tr>';
echo'                                <td>A</td>';
echo'                                <td>Computer Engineering</td>';
echo'                                <td>20 Years old</td>';
echo'                                <td>Mississauga</td>';
echo'                        </tr>';
echo'                        <tr>';
echo'                                <td>B</td>';
echo'                                <td>Computer Engineering</td>';
echo'                                <td>19 Years old</td>';
echo'                                <td>Vancouver</td>';
echo'                        </tr>';
echo'                        <tr>';
echo'                                <td>C</td>';
echo'                                <td>Computer Engineering</td>';
echo'                                <td>19 Years old</td>';
echo'                                <td>Vancouver</td>';
echo'                        </tr>';
echo'                        <tr>';
echo'                                <td>D</td>';
echo'                                <td>Computer Engineering</td>';
echo'                                <td>19 years old</td>';
echo'                                <td>Ottawa</td>';
echo'                        </tr>';
echo'                </tbody>';
echo'        </table>';
echo'        <script type="text/javascript">';
echo'           $(function(){';
echo'             $(#"demoTable").DataTable({';
echo'               dom: \'Bfrtip\',';
echo'                 buttons: [\'csv\',\'excel\', \'copy\'],';
echo'                   stripeClasses: [ \'odd\', \'even\']';
echo'                 });';
echo'       })';
echo'</script>';
echo'</body>';
?>                                                                    

 

 

Actually I went on a php code checker and my main mistakes were syntax errors. Since I already had th code and I echoed everything, I did it in chain, writting echo, 'down', etc. Same thing for the end : ';   Sometimes instead of " '; " I had " ;' " which obviously doesn't work. And all the stuff the other guys said.

 

 

 

36 minutes ago, vorticalbox said:

not only does it look much better but it is a useless waste php processing. 

 

3 hours ago, mariushm said:

Yeah,  and you know you can just say something like this :

 


echo 'This is first line
This is the next line 
here\'s more text. ';

and it would work;

 

and you can theoretically also use the HEREDOC syntax :

 


<?php
$text = <<<SOMEKEYWORD
This is first line
This is the next line 
here's more text.                      
SOMEKEYWORD;
echo $text;                      
?>

The text that starts after the line with <<< and keyword up to the line with just the keyword on it is treated as if it's entered between double quotes  ( " " ) but you don't have to escape the " characters  and some escaped combos like \t for tab, \n for newline would be converted to the proper characters.

This style of writing is rarely used, this website's code doesn't even parse it correctly.

 

 

6 hours ago, Cruorzy said:

Easiest fix would have been to remove the php tag and the echo's just make it "normal" html.

Only open a php tag when its needed like 


<p><?php echo htmlentities($string); ?></p>

 

Yep thanks for the input. Started php very recently and wanted to try something unconventional.

Link to comment
https://linustechtips.com/topic/781131-php-html-halp/#findComment-9851157
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×