Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

IT 3119 – Web Development (PHP/MySQL)

FINALS
Name: Jayson Pareño
Course: BSIT
Section: 3A

Module 9
Exercise 1
No. 4

Source Code:

<?php
$servername = "localhost:3308";
$username = "root";
$password = "";
$database = "";

$conn = mysqli_connect($servername, $username, $password, $database);

if (mysqli_connect_error())
{
die("Connection failed: " . mysqli_connect_error());
} echo "Connection successfully established!<br>";

//$conn->closes();
?>

Output:
No. 6

Source Code:

<?php
$servername = "localhost:3308";
$username = "root";
$password = "";
$database = "";

$conn = mysqli_connect($servername, $username, $password, $database);

if (mysqli_connect_error())
{
die("Connection failed: " . mysqli_connect_error());
} echo "Connection successfully established!<br>";

//Create database

$sql = "CREATE DATABASE DB_user";

if (mysqli_query($conn, $sql)) {
echo "Database was successfully created";
}
else {
echo "ERROR: Could not able to excute $sql. " . mysqli_error($conn);
}
Output:

No. 7
No. 8

No. 9
No. 11

Source Code:

$sql = "CREATE TABLE tbl_user (


user_id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50) NOT NULL,
password VARCHAR(50) NOT NULL,
birthday DATE,
gender CHAR(6))";

if (mysqli_query($conn, $sql)) {
echo "The table was successfully created";
}
else {
echo "ERROR: Could not able to execute $sql." . mysqli_error($conn);
}

Output:
No. 12
No. 14 , 15, 16
Source Code:

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>

<?php
include 'conn[Pareno].php';
if(isset($_POST['btn_save']))
{
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$password=$_POST['password'];
$birthday=$_POST['birthday'];
$gender=$_POST['gender'];

//Insert Into Table


$sql= "Insert into tbl_user values(default,'$firstname','$lastname','$email','$password','$birthday','$gender')";
if(mysqli_query($conn,$sql))
{
echo "New Account successfully created";
}
else
{
echo "Error: Could not able to execute $sql.". mysqli_error($conn);
}
$conn->close();
}
?>
<div class="cont_ord">
<legend>Form</legend>
<div class='field_container'>
<form action="" method="post">
<div class='cont_details'>
<fieldset>
<legend>Contact Details</legend>
<label for="Firstname">First Name</label>
<br>
<input type="text" name="firstname"/>
<br>
<label for="Lastname">Last Name</label>
<br>
<input type="text" name="lastname"/>
<br>
<label for="Email">Email</label>
<br>
<input type="text" name="email"/>
<br>
<label for="Password">Password</label>
<br>
<input type="password" name="password"/>
<br>
<label for="Birthday">Birthday</label>
<br>
<input type="text" name="birthday"/>
<br>
<label for="Gender">Gender</label>
<br>
<input type="text" name="gender"/>
<br>
</fieldset>
</div>
<br>
<input type="submit" name="btn_save" value="Submit"/>
<br>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
Output;
No. 19
Source Code:

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
include 'conn[Pareno].php';
?>
<table width="100%" border="1" style="border-collapse:collapse;">
<thead>
<th>User ID</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
<th>Password</th>
<th>Birthday</th>
<th>Gender</th>
<th>Delete</th>
</thead>
<tbody>
<?php
$count=1;
$sel_query= "SELECT * FROM tbl_user;";
$result=mysqli_query($conn,$sel_query);
while($row=mysqli_fetch_assoc($result)) {?> -Confidential-
<tr>
<td align="center"><?php echo $row['user_id']; ?></td>
<td align="center"><?php echo $row['firstname']; ?></td>
<td align="center"><?php echo $row['lastname']; ?></td>
<td align="center"><?php echo $row['email']; ?></td>
<td align="center"><?php echo $row['password']; ?></td>
<td align="center"><?php echo $row['birthday']; ?></td>
<td align="center"><?php echo $row['gender']; ?></td>
</tr>
<?php $count++; } ?>
</tbody>
</table>
</body>
</html>
No. 20
Module 10

Exercise 2
No. 3
Source Code:

<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
table,th,td {border:1px solid black;}
</style>
</head>
<body>
<?php
include 'conn[Pareno].php';
?>
<table width="100%" border="1" style="border-collapse:collapse;">
<thead>
<th>User ID</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
<th>Password</th>
<th>Birthday</th>
<th>Gender</th>
<th>Update</th>
</thead>
<tbody>
<?php
$count=1;
$sel_query= "SELECT * FROM tbl_user;";
$result=mysqli_query($conn,$sel_query);
while($row=mysqli_fetch_assoc($result)) {?> -Confidential-
<tr>
<td align="center"><?php echo $row['user_id']; ?></td>
<td align="center"><?php echo $row['firstname']; ?></td>
<td align="center"><?php echo $row['lastname']; ?></td>
<td align="center"><?php echo $row['email']; ?></td>
<td align="center"><?php echo $row['password']; ?></td>
<td align="center"><?php echo $row['birthday']; ?></td>
<td align="center"><?php echo $row['gender']; ?></td>
<td align="center">
<a href="update[Pareno].php?user_id=<?php echo $row["user_id"];?>">Update</a>
</td>
</tr>
<?php $count++; } ?>
</tbody>
</table>
</body>
</html>
Exercise 2
No. 5
Source Code:

<?php
include 'conn[Pareno].php';

$user_id=$_REQUEST['user_id'];

$query= "SELECT * from tbl_user where user_id = '$user_id'";


$result = mysqli_query($conn,$query) or die (mysqli_error());
$row=mysqli_fetch_assoc($result);

?>

<!DOCTYPE HTML>
<html>
<head>
<title></title>
</head>
<body>

<?php

if(isset($_POST['btn_update'])){
$user_id=$_REQUEST['user_id'];
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$password=$_POST['password'];
$birthday=$_POST['birthday'];
$gender=$_POST['gender'];

$sql= "UPDATE tbl_user SET firstname='$firstname',lastname='$lastname',email='$email',


password='$password',birthday='$birthday',gender='$gender' where user_id='$user_id'";
if(mysqli_query($conn,$sql)){
echo "records was successfully updated.";
}
else{
echo "ERROR: Could not able to execute $sql.". mysqli_error($link);
}
header("Location:usermanagement[Pareno].php");
$conn->close();
}
?>
No. 6

<div id="wrap">
<div class="cont_ord">
<legend>Form</legend>
<div class='field_container'>
<form action="" method="post">
<div class='cont_details'>
<fieldset>

<legend>Contact Details</legend>
<label for="Firstname">User ID</label>
<br>
<input type="text" name="user_id" value="<?php echo $row['user_id'];?>"/>
<br>
<label for="Firstname">First Name</label>
<br>
<input type="text" name="firstname" value="<?php echo $row['firstname'];?>"/>
<br>
<label for="Lastname">Last Name</label>
<br>
<input type="text" name="lastname" value="<?php echo $row['lastname'];?>"/>
<br>
<label for="Email">Email</label>
<br>
<input type="text" name="email" value="<?php echo $row['email'];?>"/>
<br>
<label for="Password">Password</label>
<br>
<input type="password" name="password" value="<?php echo $row['password'];?>"/>
<br>
<label for="Birthday">Birthday</label>
<br>
<input type="text" name="birthday" value="<?php echo $row['birthday'];?>"/>
<br>
<label for="Gender">Gender</label>
<br>
<input type="text" name="gender" value="<?php echo $row['gender'];?>"/>
<br>
</fieldset>
</div>
<br>
<input type="submit" name="btn_update" value="update"/>
<br>
</form>
</div>
</div>
</div>
</body>
</html>
No. 7

No. 8
No. 9

No. 12
No. 13

No. 14

You might also like