Jump to content
Larry Ullman's Book Forums

This Has To Be The Dumbest Question


Recommended Posts

I am reviewing several books on how to build a truly dynamic website driven by a SQL database. I downloaded the samples (Mac OSX 10.5.x). I click on the HTML file dept_form.html and it comes up in Safari (I can open it also with FF). But when I click on the "go" button the php file does not "run" but displays.

 

file:///Users/rob/Downloads/ajax_scripts/dept_results.php?did=1

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<title>Employees by Department</title>

<style type="text/css" media="all">@import "style.css";</style>

</head>

<body>

<h1>Department Employees</h1>

<?php # dept_results.php

 

// Validate the received department ID:

$did = 0; // Initialized value.

if (isset($_GET['did'])) { // Received by the page.

$did = (int) $_GET['did']; // Type-cast to int.

}

 

// Make sure the department ID is a positive integer:

if ($did > 0) {

 

// Get the employees from the database...

 

// Include the database connection script:

require_once('mysql.inc.php');

 

// Query the database:

$q = "SELECT * FROM employees WHERE department_id=$did ORDER BY last_name, first_name";

$r = mysql_query($q, $dbc);

 

// Check that some results were returned:

if (mysql_num_rows($r) > 0) {

 

// Retrieve the results:

while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) {

 

echo "<p><span class=\"name\">{$row['last_name']}, {$row['first_name']}</span><br />

<strong>Email</strong>: {$row['email']}<br />

<strong>Phone Extension</strong>: {$row['phone_ext']}

</p>\n";

 

} // End of WHILE loop.

 

} else { // No employees.

echo '<p class="error">There are no employees listed for the given department.</p>';

}

 

mysql_close($dbc);

 

} else { // Invalid department ID!

echo '<p class="error">Please select a valid department from the drop-down menu in order to view its employees.</p>';

}

 

?>

</body>

</html>

 

I have to be doing something incredibly stupid.

 

Rob

Link to comment
Share on other sites

It sounds like you are not using a web server program on your computer. Are you running XAMPP or MAMPP? If not your scripts will not work. You cannot just open them in a web browser, you first have to have a server read the PHP code which will then send the html to the browser.

  • Upvote 1
Link to comment
Share on other sites

Yes there is a MAMPP stack running.

 

I tried http://localhost//Users/rob/Downloads/ajax_scripts/dept_form.html

 

and got The requested URL /Users/rob/Downloads/ajax_scripts/dept_form.html was not found on this server..

 

http:/localhost// shows the default index page and I can run http://localhost//testphp (which is the typical <?php phpinfo(); ?> file).

Link to comment
Share on other sites

If you're using just http://localhost, then you're probably using the Mac's Apache, not MAMP (which is normally localhost:8888). Second, you need to be familiar with the Web root directory, which is where the files should go. localhost with MAMP would point to /Applications/MAMP/htdocs, by default, so you need to put your files there.

 

Also, the code you're using seems to be from my Ajax book, which assumes sound knowledge of PHP and MySQL. You'd be much better off starting with my "PHP for the Web: Visual QuickStart Guide (4th Edition)" book (the one that goes with this forum). That book also goes into this exact topic in great detail and repeatedly.

Link to comment
Share on other sites

Correct. It is the default on PHP Mac 10.5.x

 

I have your PHP / MySQL book but it is the second edition and things are different since Tiger. I used it to learn PHP itself.

 

I am now trying to learn how to do a very, very, very interactive website. The users clicks around on the page and it is reconstructed (including new links) with each click. The "action" of each click is recorded in the database. Think of a chess game, or better yet a game of dominos (no set grid). If the user quits the database knows the status of the board game. Each time the user makes a move (clicks) the board is updated (i.e. the database knows which dominos are out, which are placed, who placed them, and where they are...

 

I forgot about web root directory. I have another website(sic) there. Do I have to replace all those files with your example set, or should I change web root?

Link to comment
Share on other sites

 Share

×
×
  • Create New...