Question

In: Computer Science

PHP/SQL Lab 1 Consider the banking example we used in the SQL in-class exercises: branch (branch-name,...

PHP/SQL Lab 1 Consider the banking example we used in the SQL in-class exercises:

branch (branch-name, branch-city, assets)

customer (customer-name, customer-street, customer-city)

account (account-number, branch-name, balance)

loan (loan-number, branch-name, amount)

depositor (customer-name, account-number)

borrower (customer-name, loan-number)

Write PHP code for the following problems:

1. Create a php file to display the names and cities of customers who have an account at Downtown branch from the web.

2. Create the corresponding html and php files so that a user can insert the following customer into the database from a web browser. After the insertion, display all the customers from the web. “Jane Doe”, “401 Rosemont Ave”, “Frederick” Submission:

Submit a softcopy of the html and php files and a document containing screenshots of web outputs with URL included for both problems

Solutions

Expert Solution

1). ANSWER :

GIVENTHAT :

Answer 1:

<?php
// you have to give username,password and databasename of your SQL Server bellow
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Retrive name and cities of customers who have an acount at Downtown branch
$sql = "select customer-name, customer-city from customer where customer-name in (select distinct customer-name from depositor, account where depositor.account-number=account.account-number and account.branch-name='Downtown')";
$result = $conn->query($sql);

if ($result->num_rows > 0)
{
// output result in each row
while($row = $result->fetch_assoc())
   {
echo "Name: ". $row['customer-name']. " " . $row["customer-city"] . "<br>";
}
}

else
{
echo "0 results";
}

$conn->close();
?>

Answer 2:  

HTML file

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>


<form name="form1" method="post" action="insert_ac.php">
<table width="366" border="5">
<tr>
<td> <strong>Enter Customer Name:</strong></td>
<td> <input type="text" name="name"> </td>
</tr>
<tr>
<td><strong> Enter Customer Street: </strong></td>
<td> <input type="text" name="street"></td>
</tr>
<tr>
<td><strong> Enter Customer City: </strong></td>
<td> <input type="text" name="city"> </td>
</tr>

<tr>
<td> </td> </tr>
<tr> </tr>
<tr>
<td> <input type="submit" value="Submit"></td>

<td> </td>
</tr>

</table>
</form>

</body>

</html>
</body>
</html>

PHP file ie PHP code to insert customer data into database File name : insert_ac.php

<?php

$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name


// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Get values from form
$name=$_POST['name'];
$street=$_POST['street'];
$city=$_POST['city'];

// Insert data into mysql   
$sql="INSERT INTO customer(customer-name, customer-street, customer-city)VALUES('$name', '$street', '$city')";
$result=mysql_query($sql);

// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='insert.php'>Back to main page</a>";
}

else {
echo "ERROR";
}
?>

<?php
// close connection
mysql_close();
?>

PHP code to display all customers from the database file name :displaycustomer.php


<?php

// you have to give username,password and databasename of your SQL Server bellow
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Retrieve all the customer information
$sql = "SELECT * FROM customer";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0)
{
// output data of each row
while($row = mysqli_fetch_assoc($result))
   {
       $customername=$row['customer-name'] ;
       $customerstreet=$row['customer-street'] ;
       $customercity=$row['customer-city'] ;
       echo $customername.",".$customerstreet.",".$customercity;
}
}

else
{
echo "0 results";
}

mysqli_close($conn);
?>


Related Solutions

Problem 1) Consider the example we used in class on daily activity and obesity. Briefly, 10...
Problem 1) Consider the example we used in class on daily activity and obesity. Briefly, 10 lean and 10 obese volunteers were recruited to wear a sensor that monitored their every move for 10 days. The time that each subject spent walking/standing, sitting, and lying down were recorded. For more details see example 21.2 in the text. In addition to the variable we looked at in class, the data were analyzed to see if there was a difference in the...
SQL query exercises: Consider the following database schema:                Product(maker, model, type)              &
SQL query exercises: Consider the following database schema:                Product(maker, model, type)                PC(model, speed, ram, hd, rd, price)                Laptop(model, speed, ram, hd, screen, price)                Printer(model, color, type, price) Consider the Drivers-Cars-Reserves DB for a small rental car company:                Drivers(id, name, rating, age)                Cars(vin, maker, model, year, color)                Reserves(did, vin, date) Give SQL statement each of the following operations: Find the colors of cars reserved by Smith. Find all id’s of drivers who have a...
For today's lab we will be using the Car Object Class which we built in Lab...
For today's lab we will be using the Car Object Class which we built in Lab 1. I have attached my solution if you would prefer to use my solution instead of your own solution. We will working on remembering how to build sub-classes and user interfaces. So we will be creating new Java files for: An Interface called GreenHouseGasser Requires a method called CO2() which returns how much carbon dioxide the Object produces. Make sure to update Car so...
1. PHP OOP Create a complete PHP enabled website that defines and uses a PineApple class...
1. PHP OOP Create a complete PHP enabled website that defines and uses a PineApple class in PHP. The class has following members. Properties $color: string type $taste: string type $weight: number type Standard constructor, with 3 parameters Member functions eat(): no return, no parameter, print a short paragraph in English to describe how to eat a pineapple. grow(): no return, no parameter, print a short paragraph in English to describe how to grow a pineapple plant. display(): no return,...
In C++ In this lab we will be creating a stack class and a queue class,...
In C++ In this lab we will be creating a stack class and a queue class, both with a hybrid method combining linked list and arrays in addition to the Stack methods(push, pop, peek, isEmpty, size, print) and Queue methods (enqueue, deque, peek, isEmpty, size, print). DO NOT USE ANY LIBRARY, implement each method from scratch. Both the Stack and Queue classes should be generic classes. Don't forget to comment your code.
JAVAFX LAB 2 1. The Soda class has two fields: a String for the name and...
JAVAFX LAB 2 1. The Soda class has two fields: a String for the name and a double for the price. 2. The Soda class has two constructors. The first is a parameterized constructor that takes a String and a double to be assigned to the fields of the class. The second is a copy constructor that takes a Soda object and assigns the name and price of that object to the newly constructed Soda object. 3. The Soda class...
with PHP Create a class called Employee that includes three instance variables—a first name (type String),...
with PHP Create a class called Employee that includes three instance variables—a first name (type String), a last name (type String) and a monthly salary int). Provide a constructor that initializes the three instance data member. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its 0. Write a test app named EmployeeTest that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary....
Lab 7   - Rectangle class-   (Lec. 7) 1.) Create a new project and name it:    Rectangle...
Lab 7   - Rectangle class-   (Lec. 7) 1.) Create a new project and name it:    Rectangle /* OUTPUT: Enter the width of the court: 60 Enter the length of the court: 120 The width of the court is 60 feet. The length of the court is 120 feet. The area of the court is 7200 square feet. Press any key to continue . . . */ 2.) Create the following 3 files: Rectangle.h Rectangle.cpp Source.cpp 3.) Write a program that...
We started creating a Java class for Car. In this lab we are going to complete...
We started creating a Java class for Car. In this lab we are going to complete it in the following steps: 1- First create the Car class with some required instance variables, such make, model, year, price, speed, maxSpeed, isOn, isMoving, and any other properties you like to add. 2- Provide couple of constructors for initializing different set of important properties, such as make, model, year, and price. Make sure that you do not repeat initialization of instance variables in...
Create a PHP class named "User" with the following private fields: name, birthdate in yyyy/mm/dd format,...
Create a PHP class named "User" with the following private fields: name, birthdate in yyyy/mm/dd format, age, and department. In the class, include getter and setter methods to get and set the values of those variables. Author a data entry webform using HTML text input boxes and a submit button. When the user clicks on the submit button, a "User" class is instantiated and the new User object's fields are populated. The HTML input boxes correspond to the field in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT