Question

PHP Programming Question. Use the techniques you learned so far to create an Address Book application...

PHP Programming Question.

Use the techniques you learned so far to create an Address Book application that stores names, e-mail addresses, and phone numbers in a text file. Validate all input fields and include functionality that allows the user to view the address book. Also, include code that sorts the address book by name and deletes duplicate entries.

Each page in the application should have a link back to the main page.

Be creative and add extra features if you want but make sure the minimum requirements are complete first.

At a minimum observe the following standards:

- Complete - The application works and performs as expected. No run time errors.

- Style - good convention, programming style, readability. Include appropriate comments in the code.

- Validation - check for missing and malformed data.

- Documentation - List and describe the features of the application. Imagine them being on the outside of a product box. They can be in bullet form.

Additional information:

First of all, HTML should be well-formed with appropiate attributes like title. Here is a short guide that you should follow.
http://www.w3schools.com/html/html5_syntax.asp

Here are some points on PHP Coding Style that will be enforced in homework and projects.

- Indentation (tabs) should be 4 spaces.
- Be consistant with variable names. You can use camel case or _ to delimit words, but don't switch. I use camel case.
- Constant names should be UPPERCASE, with an UNDER_SCORE between words.    
- Every function should have a comment explaining what it does
- Keep functions to about 30 lines at most. This rule forces you to break up long functions into smaller, more succince functions.
- A comment explaining the purpose of a script should be in a standard format. Here is an example        

/**
   Script to manipulate widgets.
   Solves homework assignment #3
   @author Harry Hacker
   @version 1.01 2015-02-15
*/

- Include a document block before every function, indicating the purpose and describing the parameters. Fro example: 

/**
 * Calls var_dump for a variable wrapped in <pre>
 * @param $Var - variable to be displayed
 * @param $Name - name of the variable
 * @return void
 * @author  Mick Jagger
 */
function myVarDump($Var, $Name) 

- Leave a blank line after every function
- Define each variable just before it is used for the first time
- Do not define two variables on the same line:
- Use blank lines to separate parts of a method that are logically distinct.
- If a statement takes more than one line, add an indentation level for the continuation
- Comments should be used to indicate what the code is doing. 
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Address Book Name Phone Email Admin Add Contact Alexa 430-555-2252 suhine@ fakeaddress.comEdit Remove Edit Remove Edit Remove

To create this database you need to execute this code:

CREATE TABLE address (id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(30), phone VARCHAR(30), email VARCHAR(30));
INSERT INTO address (name, phone, email) VALUES ( "Alexa", "430-555-2252", "[email protected]"), ( "Devie", "658-555-5985", "[email protected]" )

Connect to the Database

<html>
<head>
<title>Address Book</title>
</head>
<body>

<?php // Connects to your Database mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error()); mysql_select_db("address") or die(mysql_error());

Add a Contact

if ( $mode=="add")
{
Print '<h2>Add Contact</h2>
<p>
<form action=';
echo $PHP_SELF;
Print '
method=post>
<table>
<tr><td>Name:</td><td><input type="text" name="name" /></td></tr>
<tr><td>Phone:</td><td><input type="text" name="phone" /></td></tr>
<tr><td>Email:</td><td><input type="text" name="email" /></td></tr>
<tr><td colspan="2" align="center"><input type="submit" /></td></tr>
<input type=hidden name=mode value=added>
</table>
</form> <p>';
}
if ( $mode=="added")
{
mysql_query ("INSERT INTO address (name, phone, email) VALUES ('$name', '$phone', '$email')");
}

Updating Data

if ( $mode=="edit")
{
Print '<h2>Edit Contact</h2>
<p>
<form action=';
echo $PHP_SELF;
Print '
method=post>
<table>
<tr><td>Name:</td><td><input type="text" value="';
Print $name;
print '" name="name" /></td></tr>
<tr><td>Phone:</td><td><input type="text" value="';
Print $phone;
print '" name="phone" /></td></tr>
<tr><td>Email:</td><td><input type="text" value="';
Print $email;
print '" name="email" /></td></tr>
<tr><td colspan="2" align="center"><input type="submit" /></td></tr>
<input type=hidden name=mode value=edited>
<input type=hidden name=id value=';
Print $id;
print '>
</table>
</form> <p>';
}
if ( $mode=="edited")
{
mysql_query ("UPDATE address SET name = '$name', phone = '$phone', email = '$email' WHERE id = $id");
Print "Data Updated!<p>";
}

Removing Data

if ( $mode=="remove")
{
mysql_query ("DELETE FROM address where id=$id");
Print "Entry has been removed <p>";
}

The Address Book

$data = mysql_query("SELECT * FROM address ORDER BY name ASC")
or die(mysql_error());
Print "<h2>Address Book</h2><p>";
Print "<table border cellpadding=3>";
Print "<tr><th width=100>Name</th><th width=100>Phone</th><th width=200>Email</th><th width=100 colspan=2>Admin</th></tr>"; Print "<td colspan=5 align=right><a href=" .$_SERVER[’PHP_SELF’]. "?mode=add>Add Contact</a></td>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr><td>".$info['name'] . "</td> ";
Print "<td>".$info['phone'] . "</td> ";
Print "<td> <a href=mailto:".$info['email'] . ">" .$info['email'] . "</a></td>";
Print "<td><a href=" .$_SERVER[’PHP_SELF’]. "?id=" . $info['id'] ."&name=" . $info['name'] . "&phone=" . $info['phone'] ."&email=" . $info['email'] . "&mode=edit>Edit</a></td>"; Print "<td><a href=" .$_SERVER[’PHP_SELF’]. "?id=" . $info['id'] ."&mode=remove>Remove</a></td></tr>";
}
Print "</table>";
?>
</body>
</html>

Add a comment
Know the answer?
Add Answer to:
PHP Programming Question. Use the techniques you learned so far to create an Address Book application...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • LANGUAGE JAVASCRIPT, PHP Need help with PHP and ajax code. The user needs to login but,...

    LANGUAGE JAVASCRIPT, PHP Need help with PHP and ajax code. The user needs to login but, I keep getting an error that I coded "Wrong username and password!" ***PLEASE DONT GIVE ME A NEW CODE THAT IS NOWHERE NEAR THE CODE I SUBMITTED***** PLEASE LOOK AT THE CODE AND SEE ANY ISSUES login.html <!DOCTYPE html> <html> <head> <title>login popup</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <style type="text/css"> body { background-color: white; } </style> </head> <body> <center> <h1 style="text-align: center;"> Login </h1> <form>             Login ID:...

  • PHP Programming In this project, you will create a Web page that allows visitors to your...

    PHP Programming In this project, you will create a Web page that allows visitors to your site to sign a guest book that is saved to a database. Create a new document in your text editor and type the <!DOCTYPE> declaration, <html> element, document head, and <body> element. Use the strict DTD and “Guest Book” as the content of the <title> element. Add the following text and elements to the document body: <h2>Enter your name to sign our guest book</h2>...

  • Programming

    Project Information: Develop a complete working application in C++ as a part of your DSA semester project. This may be an individual effort or a group contribution as per your personal preferences. In case of a group project, the maximum group size is to be two students only. Please ensure that your application should be a modular programming based solution to a problem employing the maximum concepts of data structure and algorithms (like stack, queues, link lists, and trees). You can take ‘help’ (and not copy+paste) from the Internet and other resources as long as you clearly understand and refer them in your program. Properly comment your program and use good programming practices (proper indenting, meaningful variable and function names, comments etc.)  Project Detail: Design and develop an application to automate a Library Management System. The detail of the application is as below: Your application should have a proper login. Functionality to Add, Delete, Search and Modify records of the books. A detail file (txt or binary) that includes the record of the books along with all the attributes like name of the book, author of the book, domain of the book (e.g computer science, sociology), publishing date. A function that computes how many books are in the library. A function that computes how many books of specific domain has been chosen by the applicant.  Application code must be divided as separate (.h, .cpp) files. Project Deliverable: All source code files. A project report comprising: Acknowledgement Problem Statement Objectives Salient features of your application Detail of each module of your application. A proper and understandable UML diagram of your application. Conclusion Note: Report should be properly formatted and it is mandatory to use English without grammatical mistakes.

  • Requirements Create an Address Book class in Java for general use with the following behaviors: 1....

    Requirements Create an Address Book class in Java for general use with the following behaviors: 1. Constructor: public Address Book Construct a new address book object. • A contact has four fields: first name, last name, email and phone. (There could be more information for a real contact. But these are sufficient for the assignment.) . The constructor reads from the disk to retrieve previously entered contacts. If previous contacts exist, the address book will be populated with those contacts...

  • javascript questions Declare an empty deck array. Use a loop to fill the array with string values that represent the 52 cards of a normal deck. The numbers go from 1 to 13 with 1 for an ace, 11 for...

    javascript questions Declare an empty deck array. Use a loop to fill the array with string values that represent the 52 cards of a normal deck. The numbers go from 1 to 13 with 1 for an ace, 11 for a jack, 12 for a queen, and 13 for a king. The suits are C for clubs, D for diamonds, H for hearts, and S for spades. Here’s the list of 52 values: 1C, …, 13C, 1D, …, 13D, 1H,...

  • INSTRUCTIONS #6. Your science teacher has asked you to create an application that displays how much...

    INSTRUCTIONS #6. Your science teacher has asked you to create an application that displays how much a person would weigh on the following planets: Venus, Mars, and Jupiter. The application's interface should allow the user to enter the person's weight on Earth. Perform the steps involved in creating an OO application. (See the Note at the beginning of the Exercises section.) Include a button for clearing the screen. . Create an application, using the following names for the solution and...

  • Modify an application that lets users add tasks to a list so the tasks can also...

    Modify an application that lets users add tasks to a list so the tasks can also be deleted when they’re completed. 1. In the HTML file, enclose the text for each of the three existing list items in a <p> element. Then, Add buttons like the ones shown above preceding the <p> elements. No ids or names are required for these buttons, but they should be assigned to the class named “delete”. 2. In the JavaScript file, modify the event...

  • Programming language C. A small U-Pick farm sells five different U-Pick citrus fruit products whose retail...

    Programming language C. A small U-Pick farm sells five different U-Pick citrus fruit products whose retail prices are: 1. Sugarbells - $1.99/lb, 2. Honeybells - $2.39/lb, 3. Red Grapefruit $1.69/lb, 4. Navel Oranges - $1.49/lb, 5. Pomelo - $1.89/lb. Write a program that allows the user to select one or more products, input the weights of each product, and calculate the total amount due. The farm only accepts cash. Your program will take input of the cash received and calculate...

  • Please solve the following problem with programming using proper data structures. (Programming Language: Python) A similar...

    Please solve the following problem with programming using proper data structures. (Programming Language: Python) A similar application to the parentheses matching problem comes from hypertext markup language (HTML). In HTML, tags exist in both opening and closing forms and must be balanced to properly describe a web document. This very simple HTML document: Example> Hello, world is intended only to show the matching and nesting structure for tags in the language. Write a program that can check an HTML document...

  • URGENT HELP NEEDED: JQuery. PLEASE POST SCREEN SHOTS Task 1: Downloading jQuery Right-click the link to...

    URGENT HELP NEEDED: JQuery. PLEASE POST SCREEN SHOTS Task 1: Downloading jQuery Right-click the link to download the uncompressed latest version of jQuery Copy the jQuery.x.x.x.js file in the folder and specified as source file. Task 2: Download and install HTML-Kit 1. Navigate to htmlkit.com. 2. Click Download HTML-Kit 292. After it downloads, launch HKSetup.exe. Choose Full installation (the default) Uncheck Yes, download and install HTML-Kit Tools Trial. 6. Click Next>Finish. Task 3: Creating a Simple jQuery Application Launch HTML-Kit....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT