tech_support databse using PHP and Mysql. Make a View/Update Customer project us
ID: 3730022 • Letter: T
Question
tech_support databse using PHP and Mysql. Make a View/Update Customer project using html that: When the user clicks the Update Customer button for a customer, the application updates the database, and shows the results on the next page after the button is clicked. The fields for this project are - First Name:, Last Name:, Adress:, City:, State:, Postal Code:, Country:, Phone:, Email:, and Password. I need a drop-down list for the Country: field that will select the country the customer is from (I need to display all countries that are available in the countries table in the tech_support database). I also need a link at the bottom of the first page that says Search Customers to go to another page called Search Customers.
Explanation / Answer
connect.php
<?php
$connection = mysqli_connect('localhost', 'root', '');
if (!$connection){
die("Database Connection Failed" . mysqli_error($connection));
}
$select_db = mysqli_select_db($connection, 'test');
if (!$select_db){
die("Database Selection Failed" . mysqli_error($connection));
}
?>
Home.php
<?php
include("connect.php");
$sql = "SELECT * FROM customer";
$result = mysqli_query($connection,$sql);
if (mysqli_num_rows($result) > 0) {
echo "<table border='1'>";
echo "<tr>";
echo "<th>id</th>";
echo "<th>First Name</th>";
echo "<th>Last Name</th>";
echo "<th>Email</th>";
echo "<th>Password</th>";
echo "<th>Phone</th>";
echo "<th>Address</th>";
echo "<th>State</th>";
echo "<th>City</th>";
echo "<th>Postal Code</th>";
echo "<th>Action</th>";
echo "</tr>";
while($row = mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td>" . $row['Id'] . "</td>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "<td>" . $row['Email'] . "</td>";
echo "<td>" . $row['Password'] . "</td>";
echo "<td>" . $row['Phone'] . "</td>";
echo "<td>" . $row['Address'] . "</td>";
echo "<td>" . $row['State'] . "</td>";
echo "<td>" . $row['City'] . "</td>";
echo "<td>" . $row['Postalcode'] . "</td>";
echo "<td>" .'<a href="view.php?id='.$row["Id"].'" >View</a>|| <a href="update.php?id='.$row["Id"].'" >Update</a>'."</td>";
echo "</tr>";
}
}else {
echo "0 results";
}
?>
</tr>
</table>
<a href="customers.php" target="_blank">Search Customers</a>
view.php
<?php
include("connect.php");
$viewid = $_REQUEST["id"];
$sql = "SELECT * FROM customer WHERE Id='".$viewid."'";
$result = mysqli_query($connection,$sql);
if (mysqli_num_rows($result) > 0) {
echo "<table border='1'>";
echo "<tr>";
echo "<th>id</th>";
echo "<th>First Name</th>";
echo "<th>Last Name</th>";
echo "<th>Email</th>";
echo "<th>Password</th>";
echo "<th>Phone</th>";
echo "<th>Address</th>";
echo "<th>State</th>";
echo "<th>City</th>";
echo "<th>Postal Code</th>";
echo "</tr>";
while($row = mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td>" . $row['Id'] . "</td>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "<td>" . $row['Email'] . "</td>";
echo "<td>" . $row['Password'] . "</td>";
echo "<td>" . $row['Phone'] . "</td>";
echo "<td>" . $row['Address'] . "</td>";
echo "<td>" . $row['State'] . "</td>";
echo "<td>" . $row['City'] . "</td>";
echo "<td>" . $row['Postalcode'] . "</td>";
echo "</tr>";
}
}else {
echo "0 results";
}
?>
</tr>
</table>
<a href="home.php">Click here to go Home</a>
update.php
<?php
include("connect.php");
if (isset($_GET['submit'])) {
$Id = $_GET['Id'];
$FirstName = $_GET['FirstName'];
$LastName = $_GET['LastName'];
$Email = $_GET['Email'];
$Password = $_GET['Password'];
$Phone = $_GET['Phone'];
$Address = $_GET['Address'];
$State = $_GET['State'];
$City = $_GET['City'];
$Postalcode = $_GET['Postalcode'];
$query = "update customer set
FirstName='$FirstName', LastName='$LastName', Email='$Email',
Password='$Password',Phone='$Phone',Address='$Address',State='$State',City='$City',Postalcode='$Postalcode' where Id='$Id'";
if(mysqli_query($connection, $query)){
echo "Records were updated successfully.";
} else {
echo "ERROR: Could not able to execute $query. " . mysqli_error($connection);
}
}
if (isset($_GET['id'])) {
$update = $_GET['id'];
$sql = "SELECT * FROM customer WHERE Id='".$update."'";
$result = mysqli_query($connection,$sql);
while($row1 = mysqli_fetch_assoc($result)){
echo "<form class='form' method='get'>";
echo "<h2>Update Form</h2>";
echo "<hr/>";
echo"<input class='input' type='hidden' name='Id' value='{$row1['Id']}' />";
echo "<br />";
echo "<label>" . "First Name:" . "</label>" . "<br />";
echo"<input class='input' type='text' name='FirstName' value='{$row1['FirstName']}' />";
echo "<br />";
echo "<label>" . "Last Name:" . "</label>" . "<br />";
echo"<input class='input' type='text' name='LastName' value='{$row1['LastName']}' />";
echo "<br />";
echo "<label>" . "Email:" . "</label>" . "<br />";
echo"<input class='input' type='text' name='Email' value='{$row1['Email']}' />";
echo "<br />";
echo "<label>" . "Password:" . "</label>" . "<br />";
echo"<input class='input' type='text' name='Password' value='{$row1['Password']}' />";
echo "<br />";
echo "<label>" . "Phone:" . "</label>" . "<br />";
echo"<input class='input' type='text' name='Phone' value='{$row1['Phone']}' />";
echo "<br />";
echo "<label>" . "Address:" . "</label>" . "<br />";
echo "<textarea rows='5' cols='20' name='Address'>{$row1['Address']}";
echo "</textarea>";
echo "<br />";
echo "<label>" . "State:" . "</label>" . "<br />";
echo"<input class='input' type='text' name='State' value='{$row1['State']}' />";
echo "<br />";
echo "<label>" . "City:" . "</label>" . "<br />";
echo"<input class='input' type='text' name='City' value='{$row1['City']}' />";
echo "<br />";
echo "<label>" . "Postal Code:" . "</label>" . "<br />";
echo"<input class='input' type='text' name='Postalcode' value='{$row1['Postalcode']}' />";
echo "<br />";
echo "<input class='submit' type='submit' name='submit' value='update' />";
echo "</form>";
}
}
if (isset($_GET['submit'])) {
echo '<div class="form" id="form3"><br><br><br><br><br><br>
<Span>Data Updated Successfuly......!!</span></div>';
}
?>
<a href="home.php">Click here to go Home</a>
</body>
</head>
</html>
Hi here by i have added everything use asked except by displaying country due to shortage of time but stored country in differnt table etc.only dispalaying in drop down alone missing please comment so that i will answer that part too.rest of my codes are here
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.