I am building this web application and I am attempting to use Jquery and PHP for the scripting. The issue that I am running into while testing the page on MAMP is displaying PHP variable values. My php code runs successfully when I create a very simple test page with just basic HTML and PHP. You can see it here:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
$db = mysql_connect("localhost", "student", "student")
or die("I cannot connect to the database because: " . mysql_error());
mysql_select_db("Dealership", $db);
$result = mysql_query("SELECT COUNT( * ) AS 'Number of Cars' FROM CARS;") or die("Error in query: '$query'");
while($row = mysql_fetch_array($result))
{
$numberOfCars = $row['Number of Cars'];
}
mysql_close($db);
?>
<?php
print "<p>Number of Vehicles on the Lot: " . $numberOfCars . "Var Dump:"; var_dump($numberOfCars); print "</p>";
?>
</body>
</html>
When I try to use that same code on my webpage the value of the variable $numberOfCars will not display.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Car Dealership Portal</title>
<link rel="stylesheet" type="text/css" href="jquery.mobile.flatui.css" />
<script src="jquery-1.10.2.min.js"></script>
<script src="jquery.mobile-1.3.2.min.js"></script>
</head>
<body>
<div data-role="page">
<?php
$db = mysql_connect("localhost", "student", "student")
or die("I cannot connect to the database because: " . mysql_error());
mysql_select_db("Dealership", $db);
$result = mysql_query("SELECT COUNT( * ) AS 'Number of Cars' FROM CARS;") or die("Error in query: '$query'");
while($row = mysql_fetch_array($result))
{
$numberOfCars = $row['Number of Cars'];
}
mysql_close($db);
?>
<div data-role="panel" id="panel" data-position="right" data-theme="a" data-display="push"></div>
<div data-role="header">
<a data-iconpos="notext" data-role="button" data-icon="home" title="Home">Home</a>
<h1>Car Dealership Portal</h1>
<a data-iconpos="notext" href="#panel" data-role="button" data-icon="flat-menu"></a>
</div>
<div data-role="content" role="main">
<input type="text" placeholder="Search for a Vehicle" />
<div>
<?php print "<p>Number of Vehicles on the Lot: " . $numberOfCars . "Var Dump:"; var_dump($numberOfCars); print "</p>"; ?>
</div>
<div data-role="collapsible-set">
<div data-role="collapsible" data-collapsed="false">
<h3>Number of Appointments Today: 3</h3>
<p>Jon Snow 11:00am</p>
<p>Joffrey Baratheon 1:00pm</p>
<p>Eddard Stark 3:00pm</p>
</div>
<div data-role="collapsible">
<h3>Number of Cars in Shop: 5</h3>
<p>Porsche 911 GT3 Arya Stark</p>
<p>Nissan GTR Ygritte</p>
<p>BMW M3 Stannis Baratheon</p>
<p>Audi RS6 Avant Tywin Lannister</p>
<p>Lamborghini Aventador Petyr Baelish</p>
</div>
</div>
</div>
</div>
</body>
</html>
You can check out the code here: http://pastebin.com/GwDbHwY6
Stack Overflow wouldn't let me post the code here.