I have a basic ajax application, which will not work, instead the php code is displayed in the browser. The javascript and html seem fine. I have copied the code verbatim from here:
and this is the php:
<? session_start(); //start the session $cmd = $_GET['cmd']; $con = mysql_connect('localhost', 'root', 'indosat'); if (!con) { die('Connection to MySQL server failed: ' . mysql_error()); //show error message (mysql_error) if connection failed } mysql_select_db('ajax', $con); //select the database, in this case our database name is 'ajax' if ($cmd === 'GetEmployee') //set command value (executed from javascript ajaxlib.js) { sleep(10); //give delay about 10 seconds before execute the command //we use this sleep function so we can see the loading animation //you can edit/remove echo '<table border='1' width='100%'> <tr> <th>EmpNo</th> <th>fName</th> <th>lName</th> <th>Age</th> </tr>'; //print a table to browser to show the values $sql = 'select * from employee'; //this is query to show all records $result = mysql_query($sql); //execute the query & fill it to $result variable while ($row = mysql_fetch_array($result)) { echo '<tr> <td>' . $row['IdEmp'] . '</td> <td>' . $row['fName'] . '</td> <td> ' . $row['lName'] . '</td> <td>' . $row['Age'] . '</td> </tr>'; //print the record to the table } echo '</table>'; //close the table } mysql_close($con); //close the mysql connection ?>
I don’t see what the problem could be
edit: it is NOT the shorttags. they are enabled, andusing ‘long’ tags makes no difference.
I don’t know the answer but here’s a guide on how to solve these issues:
<?php echo phpinfo(); ?>I doubt this has anything to do with PHP and believe it’s related to Apache. Are you sure you saved the file in the right place? What is your
DocumentRootdirectory setting and where have you saved the file? Do all of the above steps work? I doubt that you reach (3), everything works fine in the test case but the original code breaks. It’s probably got something to do with the file extension (on Linux it’s case-sensitive) or where you’ve placed the file.