Intermediate Web Programming Help The local farmers are having problems with som
ID: 3572641 • Letter: I
Question
Intermediate Web Programming Help
The local farmers are having problems with some pesky crows eating their crops. As a counter-measure, they have decided to concoct some pretty scary scarecrows; in fact, most of the farmers will be constructing multiple scarecrows for their fields. To make one scarecrow, they need one pumpkin for the head, some nuts for the eyes and mouth, and a carrot for the nose. At the local Farmer’s Market everyone is selling Halloween items, but the farmers all stop at Farmer Fred’s stand because he is selling everything that they need.
Because of the increased demand for pumpkins, nuts, and carrots, Farmer Fred has asked for your help. He needs a way of displaying an up-to-date record of all the pumpkins, nuts and carrots he has in stock. Your job is to create a web-based mini-application to do this, as follows: (Write your mysql command for each of the following questions respectively and number them clearly.)
* Create a new database with the name: FredBiz
* Using a single command, create a new user named “Fred” with a password of “Farmer#Fred.” He should have full access to the FredBiz database but no other. You should use Farmer Fred’s account to access the database in your web application
* As user Fred (don’t forget to reinitialize the log file), login to mysql and create a table in FredBiz named “Halloween” with the following columns:
o id (INTEGER)
o qty (INTEGER)
o description (VARCHAR(20))
o weight (INTEGER)
* Enter the following records into the Halloween table:
id qty description weight
1 20 pumpkin 10
2 43 mixed nuts 2
3 25 pumpkin 15
4 87 bag carrots 1
5 9 pumpkin 20
6 52 mixed nuts 1
7 68 bag carrots 2
8 5 pumpkin 25
*As user Fred, login to mysql and create a table in FredBiz named “users” with the following columns:
o id (INTEGER)
o username (VARCHAR(20))
o password (VARCHAR(16))
* Enter the following records into the Halloween table:
id username password
1 batman batman123
2 jdoe jdoe123
Write a login page that will enable the user to register. For returning users such as "batman" or "jdoe", once they enter the correct username and password information they will go to the next page to specify what he/she is looking for. Please note that this next page and all the following pages should contain the username information as long as he/she is in the session.
Write an input form that will ask the user for the item he/she is looking for. Use a heading at the top that says “Fred’s Market Biz” and a smaller subheading that says “Current Inventory.”
The form should contain a text input control to enter a description of the desired item. You may use a select input control or radio buttons to choose the desired item if you prefer.
Write the corresponding target script of Fred’s MarketBiz “Current Inventory” page. The target script should contain the same heading at the top and have the same overall look and feel as the previous page with the input form. As a subheading, this page should display the name of the item the application was looking for, followed by a nicely-formatted table that contains a list of id’s, qty’s and weights of all matching items. The table headers should clearly state the information in the columns, specifying that the weight is in pounds (lbs).
Don’t forget to account for the possibility that there are no records for that item. Somewhere on the target page, put a link or a button to allow Fred to return to the original page with the input form easily.
The application should also be able to let the user who is in the system to enter new information to the “Halloween” table and to delete old information from it. Add additional buttons or links if needed.
Once the user finishes with the pages, he/she should be able to log out from the application.
Create a CSS file (external) to have the same visual effect on the web application.
Generate the MYSQL dump file for the database and its content.
Make sure to send in only one zipped file which contains
* All php, html, css, js, MYSQL dump file, and other source files necessary to implement fully the web interface.
* A text file containing any notes I will need to get started, like usernames/passwords and where to begin
Explanation / Answer
header.php
<html>
<head>
</head>
<body>
<table width="100%">
<tr>
<td align="left"><img src="corny.jpg" height="250" width="200"></td>
<td align="center"><h1>Freds Market Biz</h1></td>
<td align="right"><img src="funny_carrot.jpg" height="300" width"250"></td>
</table>
</body>
</html>
login_page.php
<!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>
<title>Login page</title>
<link rel = "stylesheet" type = "text/css" href="style1.css"/>
<meta http-equiv="Content-Type"
content="text/html; charset=UTF-8" />
</head>
<body>
<?php
require('header.php');
?>
<form method="POST" action="login_result.php">
<table border="3" width = "20%" cellpadding="1" align="center">
<th colspan='2' align="center">
<h1>Please Login</h1>
</thead>
<tr>
<td align="left" cellpadding="35"><p>User Name</td><td align="right" > <input type="text" name="user_name" /></p></td>
</tr>
<tr>
<td align="left"><p>Password</td><td align="right"> <input type="text" name="user_passwd" /></p></td>
</tr>
<tfoot>
<tr>
<td align="left"><a href="new_user.php">New user Click Here</a></td>
<td><input type="submit" value="Login" /></td>
</tfoot>
</table>
</body>
</html>
login_result.php
<html>
<head>
<title>Enter Search Data</title>
<link rel = "stylesheet" type = "text/css" href="style1.css"/>
</head>
<body>
<?php
session_start();
function show_info($data1, $data2)//function to dsiplay username or set cookie if new user
{
if (isset($_COOKIE["uname"]))
{
echo "<p align='center'>welcome back ".$_COOKIE['uname']."</p>";
}
else
{
setcookie("uname",$data2, time()+600, "/", false, 0);
echo "<p>Hello you. This may be your first visit.</p>";
}
}
function sel_veg ()
{
echo "<form method='POST' action='veg_result.php'>";
echo "<table border='2' width = '45%' cellpadding='1' align='center'>";
echo "<th colspan='2'>";
echo "<h2 align='center'>Current Inventory</h2>";
echo "</th>";
echo "<tr>";
echo "<td><p>Enter a vegtable to check current inventory</td><td align='right' > <input type='text' name='veg_sel' /></p></td>";
echo "</tr>";
echo "<tfoot>";
echo "<tr>";
echo "<td align='right'><input type='reset' value='Reset' /></a></td>";
echo "<td><input type='submit' value='Submit' /></td>";
echo "</tfoot>";
echo "</table>";
}
//print_r($_COOKIE['uname']) ;
//echo "<p>".$data1."</p>";
//echo " ";
//echo "<p>".$data2."</p>";
$name1 = trim($_POST['user_name']);
$passw = trim($_POST['user_passwd']);
//$_SESSION['sess_name'] = $name1;
//$_SESSION['sess_passw'] = $passw;
if (!get_magic_quotes_gpc()) {
}
//create connection to database fredbiz
@ $db = mysqli_connect('localhost', 'Fred', 'Farmer#Fred', 'FredBiz');
if (mysqli_connect_errno()) {
echo ' Error: Could not connect to database. Please try again later.';
exit;
}
//query users table
$query =("SELECT * FROM Users");
$result = mysqli_query($db,$query);
$num_results = mysqli_num_rows($result);
$i=0;
while ($i<10)
{
$row = mysqli_fetch_assoc($result);
//test for matching user name and password
if ($row['username'] = $name1 && $row['password'] = $passw)
{
require('header.php');
show_info($row['id'], $row['username']);
echo "<br />";
sel_veg();
break;
}
else
{
echo "<p align='center'>Sorry you must register to access database</p>";
echo "<p align='center'><a href="new_user.php">Click here to register.</a></p>";
echo "<p align='center'><a href="login page.php">Click here to return to login page.</a></p>";
break;
}
$i++;
}
?>
</body>
</html>
newFredBiz.sql
-- MySQL dump 10.13 Distrib 5.5.27, for Win32 (x86)
--
-- Host: localhost Database: FredBiz
-- ------------------------------------------------------
-- Server version 5.5.27
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `halloween`
--
DROP TABLE IF EXISTS `halloween`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `halloween` (
`id` int(6) NOT NULL AUTO_INCREMENT,
`qty` int(10) DEFAULT NULL,
`description` varchar(20) DEFAULT NULL,
`weight` int(10) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `halloween`
--
LOCK TABLES `halloween` WRITE;
/*!40000 ALTER TABLE `halloween` DISABLE KEYS */;
INSERT INTO `halloween` VALUES (1,20,'pumpkin',10),(2,43,'mixed nuts',2),(3,25,'pumpkin',15),(4,87,'bag carrots',1),(5,9,'pumpkin',20),(6,52,'mixed nuts',1),(7,68,'bag carrots',2),(8,5,'pumpkin',25);
/*!40000 ALTER TABLE `halloween` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `users`
--
DROP TABLE IF EXISTS `users`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `users` (
`id` int(6) NOT NULL AUTO_INCREMENT,
`username` varchar(20) DEFAULT NULL,
`password` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `users`
--
LOCK TABLES `users` WRITE;
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
INSERT INTO `users` VALUES (1,'batman','batman123'),(2,'jdoe','jdoe123');
/*!40000 ALTER TABLE `users` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2013-04-28 15:00:51
new_user.php
<html>
<head>
<title>New User Registration</title>
<link rel = "stylesheet" type = "text/css" href="style1.css"/>
</head>
<body>
<?php
require('header.php');
echo "<form method='POST' action='new_user_success.php'>";
echo "<table border='2' width = '45%' cellpadding='1' align='center'>";
echo "<th colspan='2'>";
echo "<h2 align='center'>Register New User</h2>";
echo "</th>";
echo "<tr>";
echo "<td><p>Enter User Name</td><td align='right' > <input type='text' name='usr_name' /></p></td>";
echo "</tr>";
echo "<tr>";
echo "<td><p>Enter Password</td><td align='right' > <input type='text' name='usr_passwd' /></p></td>";
echo "</tr>";
echo "<tfoot>";
echo "<tr>";
echo "<td align='right'><input type='reset' value='Reset' /></a></td>";
echo "<td><input type='submit' value='Submit' /></td>";
echo "</tfoot>";
echo "</table>";
?>
</body>
</html>
new_user_success.php
<html>
<head>
<title>Success!</title>
<link rel = "stylesheet" type = "text/css" href="style1.css"/>
</head>
<body>
<?php
session_start();
$uname=$_POST['usr_name'];
$upswd=$_POST['usr_passwd'];
//create connection to database fredbiz
@ $db = mysqli_connect('localhost', 'Fred', 'Farmer#Fred', 'FredBiz');
if (mysqli_connect_errno()) {
echo ' Error: Could not connect to database. Please try again later.';
exit;
}
//query to insert new values into database
$query = "INSERT INTO Users Values (NULL,'$uname','$upswd')";
$result = mysqli_query($db, $query);
if ($result)
{
echo '<p>successful registration!</p>';
}
else
{
echo '<p>fail</p>';
}
echo "<p align='center'><a href="login page.php">Click here to return to login page.</a></p>";
mysqli_close($db);
?>
</body>
</html>
style1.css
body { background-color: #177E0B
}
h1 { color: #A5A3B5;
text-align: center}
h2 { color: #A5A3B5;
}
p { color: #A5A3B5;
}
a { color: #A5A3B5;
}
div { top-padding: 1;
bottom-padding: 1}
veg_result.php
<html>
<head>
<title>Search result</title>
<link rel = "stylesheet" type = "text/css" href="style1.css"/>
</head>
<body>
<?php
require('header.php');
function show_info($data1, $data2, $data3)//function to dsiplay username or set cookie if new user
{
echo "<table border='2' width = '45%' cellpadding='1' align='center'>";
echo "<thead>";
echo "<td>Quantity</td><td>Vegetable</td><td>Weight(lb)</td>";
echo "</th>";
echo "<tr>";
echo "<td>".$data1."</td>";
echo "<td>".$data2."</td>";
echo "<td>".$data3."</td>";
echo "</tr>";
}
session_start();
$veg = trim($_POST['veg_sel']);
$_SESSION['sess_veg'] = $veg;
//function show_info($data1, $data2)//function to dsiplay username or set cookie if new user
//{
// if (isset($_COOKIE["uname"]))
// {
// echo "<p align='center'>welcome back ".$_COOKIE['uname']."</p>";
// }
// else
// {
// setcookie("uname",$data2, time()+600, "/", false, 0);
// echo "<p>Hello you. This may be your first visit.</p>";
// }
// }
//create connection to database fredbiz
@ $db = mysqli_connect('localhost', 'Fred', 'Farmer#Fred', 'FredBiz');
if (mysqli_connect_errno())
{
echo ' Error: Could not connect to database. Please try again later.';
exit;
}
//query users table
$result = mysqli_query($db, "SELECT * FROM Halloween");
$num_results = mysqli_num_rows($result);
$i=0;
while ($i<9)
{
$row = mysqli_fetch_assoc($result);
if ($row['description'] == $_SESSION['sess_veg'])
{
show_info ($row['qty'], $row['description'],$row['weight']);
//break;
}
//else
//{
//echo "you did not enter a valid item name";
//}
$i++;
}
echo "<form method='POST' action='veg_result.php'>";
echo "<table border='2' width = '45%' cellpadding='1' align='center'>";
echo "<th colspan='2'>";
echo "<h2 align='center'>Current Inventory</h2>";
echo "</th>";
echo "<tr>";
echo "<td><p>Enter a vegtable to check current inventory</td><td align='right' > <input type='text' name='veg_sel' /></p></td>";
echo "</tr>";
echo "<tfoot>";
echo "<tr>";
echo "<td align='right'><input type='reset' value='Reset' /></a></td>";
echo "<td><input type='submit' value='Submit' /></td>";
echo "</tfoot>";
echo "</table>";
echo "<p><a href="login page.php">logout</a></p>";
echo "<p align='center'><a href="new_veg.php">Click here to add a new vegetable.</a></p>";
?>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.