Jump to content
Larry Ullman's Book Forums

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 post
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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...