Note that there are some explanatory texts on larger screens.

plurals
  1. POajax displaying code instead of result
    text
    copied!<p>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:</p> <p><a href="http://arief.aeroven.com/2008/07/30/first-ajax-script-tutorial-connecting-ajax-contain-pure-htmlphpand-javascript-to-mysql-database/" rel="nofollow noreferrer">http://arief.aeroven.com/2008/07/30/first-ajax-script-tutorial-connecting-ajax-contain-pure-htmlphpand-javascript-to-mysql-database/</a></p> <p>and this is the php:</p> <pre><code>&lt;? 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 "&lt;table border='1' width='100%'&gt; &lt;tr&gt; &lt;th&gt;EmpNo&lt;/th&gt; &lt;th&gt;fName&lt;/th&gt; &lt;th&gt;lName&lt;/th&gt; &lt;th&gt;Age&lt;/th&gt; &lt;/tr&gt;"; //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 &amp; fill it to $result variable while ($row = mysql_fetch_array($result)) { echo "&lt;tr&gt; &lt;td&gt;" . $row['IdEmp'] . "&lt;/td&gt; &lt;td&gt;" . $row['fName'] . "&lt;/td&gt; &lt;td&gt; " . $row['lName'] . "&lt;/td&gt; &lt;td&gt;" . $row['Age'] . "&lt;/td&gt; &lt;/tr&gt;"; //print the record to the table } echo '&lt;/table&gt;'; //close the table } mysql_close($con); //close the mysql connection ?&gt; </code></pre> <p>I don't see what the problem could be</p> <p>edit: it is NOT the shorttags. they are enabled, andusing "long" tags makes no difference.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload