Skip to content

Instantly share code, notes, and snippets.

@arvindsvt
Created February 4, 2018 15:54
Show Gist options
  • Save arvindsvt/75fb7357d42870128345a7796ae90b56 to your computer and use it in GitHub Desktop.
Save arvindsvt/75fb7357d42870128345a7796ae90b56 to your computer and use it in GitHub Desktop.
@charset "UTF-8";
/* CSS Document */
/*66635D (gray) E54140 (red) F7EBD5 (cream) 6CC5C1 (aqua) 000000 (black) */
body
{
background-color: #F7EBD5;
font-family: sans-serif;
color: #66635D;
}
a
{
color: #E54140;
text-decoration: none;
font-weight: bold;
}
.warning
{
color: #E54140;
font-weight: bold;
}
h1
{
font-family: "Arial Black", Verdana, Helvetical,sans-serif;
background-color: #6CC5C1 ;
color: #E54140;
text-align: center;
}
header
{
background-color: #E54140;
color: #E54140;
padding:1em;
color: #F7EBD5;
text-align: center;
}
.fl
{
float: left;
}
div
{
padding-left: 1em;
}
h2
{
color: #000000;
}
li
{
font-weight: bold;
}
iframe
{
background-color:#6CC5C1;
}
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="easy.css">
<meta charset="UTF-8">
<title>Basics of PHP OOP</title>
</head>
<body>
<img class="fl" src="snap150.jpg" alt="snap">
<header>
<h1>Basic Classes for Basic Tasks I</h1>
Keeping objects clear and focused on a single task</header>
<div>
<h2>Entering Data into a Table and Retrieving it</h2>
</div>
<div>Data are entered into a table through a UI, but automatically generated data also may be entered.</div>
<br />
<form action="Client.php" method="post" target="feedback">
<div><strong>Developer Info:</strong><br />
<label for="name">Name:</label>
<input type="text" name="name" id="name">
<br />
<label for="email">Email:</label>
<input type="email" name="email" id="email">
<p />
</div>
<div><strong>Programming Language Used Most</strong><br />
<input type="radio" name="lang" id="cs" value="C#">
<label for="cs">C#:</label>
<br />
<input type="radio" name="lang" id="js" value="JavaScript">
<label for="js">JavaScript:</label>
<br />
<input type="radio" name="lang" id="php" value="PHP">
<label for="php">PHP:</label>
<br />
<input type="radio" name="lang" id="python" value="Python">
<label for="python">Python:</label>
</div>
<br />
<div>
<input type="submit" name="insert" value="Insert Data into Table">
</div>
</form>
<p />
<div><strong>Display All Data in Table with a new Form</strong>
<p />
<form action="Client.php" method="post" target="feedback">
<input type="submit" name="all" value="Display all data">
</form>
</div>
<br />
The PHP class uses 4 MySql fields to store and retrieve the information:
<ul>
<li>id</li>
<li>name</li>
<li>email</li>
<li>lang</li>
</ul>
<iframe name="feedback" seamless width="300" height="200">PHP</iframe>
<div>
<p>
<a href="EasyUpdateOOP.html">Update and Drop Files</a>
</p>
</div>
</body>
</html>
<?php
ERROR_REPORTING( E_ALL | E_STRICT );
ini_set("display_errors", 1);
function __autoload($class_name)
{
include $class_name . '.php';
}
class Client
{
//Variable to select the correct class
private $task;
//Which submit button used?
public function __construct()
{
if(isset($_POST['insert']))
{
unset($_POST['insert']);
$this->task= new DataEntry();
}
elseif(isset($_POST['all']))
{
unset($_POST['all']);
$this->task= new DataDisplay();
}
elseif(isset($_POST['update']))
{
unset($_POST['update']);
$this->task= new DataUpdate();
}
elseif(isset($_POST['kill']))
{
unset($_POST['kill']);
$this->task= new DeleteRecord();
}
}
}
$worker = new Client();
?>
<?php
class DataEntry
{
//Variable for MySql connection
private $hookup;
private $sql;
private $tableMaster;
//Field Variables
private $name;
private $email;
private $lang;
public function __construct()
{
//Get table name and make connection
$this->tableMaster="basics";
$this->hookup=UniversalConnect::doConnect();
//Get data from HTML form
$this->name=$_POST['name'];
$this->email=$_POST['email'];
$this->lang=$_POST['lang'];
//Call private methods for MySql operations
$this->doInsert();
$this->hookup->close();
}
private function doInsert()
{
$this->sql = "INSERT INTO $this->tableMaster (name,email,lang) VALUES ('$this->name','$this->email', '$this->lang')";
try
{
$this->hookup->query($this->sql);
printf("User name: %s <br/> Email: %s <br/> uses %s the most for programming.",$this->name,$this->email,$this->lang);
}
catch (Exception $e)
{
echo "There is a problem: " . $e->getMessage();
exit();
}
}
}
?>
<?php
class DataDisplay
{
//Variable for MySql connection
private $hookup;
private $sql;
private $tableMaster;
public function __construct()
{
//Get table name and make connection
$this->tableMaster="basics";
$this->hookup=UniversalConnect::doConnect();
$this->doDisplay();
$this->hookup->close();
}
private function doDisplay()
{
//Create Query Statement
$this->sql ="SELECT * FROM $this->tableMaster";
try
{
$result = $this->hookup->query($this->sql);
while ($row = $result->fetch_assoc())
{
printf("ID: %s Name: %s Email: %s <br />Computer Language: %s<p />",$row['id'], $row['name'],$row['email'],$row['lang'] );
}
$result->close();
}
catch(Exception $e)
{
echo "Here's what went wrong: " . $e->getMessage();
}
}
}
?>
<?php
class DataUpdate
{
private $hookup;
private $tableMaster;
private $sql;
//Fields
private $id;
private $name;
private $email;
private $lang;
public function __construct()
{
$this->id=intval($_POST['id']);
$this->name=$_POST['name'];
$this->email=$_POST['email'];
$this->lang=$_POST['lang'];
$this->tableMaster="basics";
$this->hookup=UniversalConnect::doConnect();
//Call each update
$this->doName();
$this->doEmail();
$this->doLang();
//Close once
$this->hookup->close();
}
private function doName()
{
$this->sql ="UPDATE $this->tableMaster SET name='$this->name' WHERE id='$this->id'";
try
{
$result = $this->hookup->query($this->sql);
echo "Name update complete.<br />";
}
catch(Exception $e)
{
echo "Here's what went wrong: " . $e->getMessage();
}
}
private function doEmail()
{
$this->sql ="UPDATE $this->tableMaster SET email='$this->email' WHERE id='$this->id'";
try
{
$result = $this->hookup->query($this->sql);
echo "Name update complete.<br />";
}
catch(Exception $e)
{
echo "Here's what went wrong: " . $e->getMessage();
}
}
private function doLang()
{
$this->sql ="UPDATE $this->tableMaster SET lang='$this->lang' WHERE id='$this->id'";
try
{
$result = $this->hookup->query($this->sql);
echo "Computer language update complete.<br />";
}
catch(Exception $e)
{
echo "Here's what went wrong: " . $e->getMessage();
}
}
}
?>
<?php
class DeleteRecord
{
//Variables for MySql connection
private $hookup;
private $sql;
private $tableMaster;
//From HTML
private $deadman;
public function __construct()
{
$this->deadman =intval($_POST['idd']);
//Get table name and make connection
$this->tableMaster="basics";
$this->hookup=UniversalConnect::doConnect();
$this->recordKill();
$this->hookup->close();
}
private function recordKill()
{
//Create Query Statement
$this->sql ="Delete FROM $this->tableMaster WHERE id='$this->deadman'";
try
{
$result = $this->hookup->query($this->sql);
printf("Record with ID=%s: has been dropped.<br />",$this->deadman );
}
catch(Exception $e)
{
echo "Here's what went wrong: " . $e->getMessage();
}
}
}
?>
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="easy.css">
<meta charset="UTF-8">
<title>Easy Update PHP-MySql OOP</title>
</head>
<body>
<img class="fl" src="snap150.jpg" alt="snap">
<header>
<h1>Basic Classes for Basic Tasks II</h1>
Keeping objects clear and focused on a single task</header>
<div>
<h2>Updating Data in a Table and Dropping Records</h2>
</div>
<div>Update all data in a record.</div>
<br />
<form action="Client.php" method="post" target="feedback">
<div><strong>Record Info:</strong><br />
<label for="id">ID Number:</label>
<input type="text" name="id" id="id" size="4">
<p />
<strong>Developer Update:</strong><br />
<label for="name">Update Name:</label>
<input type="text" name="name" id="name">
<br />
<label for="email">Update Email:</label>
<input type="email" name="email" id="email">
<p />
</div>
<div><strong>Update Programming Language Used Most</strong><br />
<input type="radio" name="lang" id="cs" value="C#">
<label for="cs">C#:</label>
<br />
<input type="radio" name="lang" id="js" value="JavaScript">
<label for="js">JavaScript:</label>
<br />
<input type="radio" name="lang" id="php" value="PHP">
<label for="php">PHP:</label>
<br />
<input type="radio" name="lang" id="python" value="Python">
<label for="python">Python:</label>
</div>
<br />
<div>
<input type="submit" name="update" value="Update Data in Record">
</div>
</form>
<p />
<form action="Client.php" method="post" target="feedback">
<div><strong>Record to Delete:</strong><br />
<label for="idd">ID Number:</label>
<input type="text" name="idd" id="idd" size="4">
<p />
<span class="warning">By clicking this button the record will be deleted forever.</span><br />
<input type="submit" name="kill" value="Permanently Delete Record">
</div>
</form>
<div><strong>Display All Data in Table with a new Form</strong>
<p />
<form action="Client.php" method="post" target="feedback">
<input type="submit" name="all" value="Display all data">
</form>
</div>
<br />
The PHP class uses 4 MySql fields to store and retrieve the information:
<ul>
<li>id</li>
<li>name</li>
<li>email</li>
<li>lang</li>
</ul>
<iframe name="feedback" seamless width="400" height="200">PHP</iframe>
<div>
<p> <a href="EasyOOP.html">Enter Records</a> </p>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment