PHP, Database Access

Download Report

Transcript PHP, Database Access

Creating A Database Driven
Website
1.
2.
3.
4.
5.
6.
Setting Up Your Web Server
Creating a Database
Creating a Webpage to Display Information From a Database
Creating a form to Add information to a Database
Registering a Domain Name
Associating a Domain Name to Your Server
Visit http://domainsforauthors.com/ to setup a free website
Your URL: http://demo.domainsforauthors.com
Cpanel URL: http://cpanel.domainsforauthors.com/
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title descriptive of the page's contents or
purpose</title>
<meta name="description" content="A longer description
of the page's contents." />
</head>
http://cis3630.org/donotuse.html
<body>
Your content goes here
</body>
</html>
Cpanel URL: http://cpanel.domainsforauthors.com/
CREATE TABLE IF NOT EXISTS `students` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`email` varchar(100) NOT NULL,
`url` varchar(100) NOT NULL,
`added` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `name` (`name`),
KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=128 ;
INSERT INTO `students` (`id`, `name`, `email`, `url`, `added`) VALUES
(2, 'Ira Cross', '[email protected]', '', '2015-09-17 18:39:55'),
(3, 'Anna Rios', '[email protected]', 'http://annarios.domainsforauthors.com/', '2015-10-27 22:43:00'),
(4, 'Troy Johnson', '[email protected]', 'http://demo.domainsforauthors.com', '2015-10-27 23:01:54'),
(5, 'Wonder Woman', '[email protected]', 'http://www.dccomics.com/characters/wonder-woman', '2015-10-27
23:50:28'),
(1, 'Junjie Low', '[email protected]', '', '2015-10-28 22:44:18');
Create new a file call it database-connect.php
<?php
$servername = "sql305.domainsforauthors.com";
$username = "dmnsf_16833743";
$password = "your_password";
$dbname = "dmnsf_16363720_database";
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Student Demo Page</title>
<meta name="description" content="A longer description of the page's contents." />
</head>
<body>
<h2>Student Demo Page</h2>
<hr />
<?php
include('database-connect.php');
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id,name,email,url,added FROM students";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo $row["id"]. $row["name"]. $row["website"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
<hr />
</body>
</html>
Create a new file called students.php
Create a php file called add-student.php You may download the
HTML here: http://cis3630.org/add-student.php-file.txt
Registering a
Domain Name
You will be presented
with multiple screens
attempting to up sell
you on with multiple,
typically unneeded
products.
Registering 2 domain
names cost $19.98
via Network
Solutions
Remember, you need to change the nameservers on a
domain via registrar control panel BEFORE adding it to
your account, it may take 24 to 72 hours to completely
update the nameservers (it usually does not take that
long):
Please verify your nameservers and/or change them to:
ns1.byet.org
ns2.byet.org
ns3.byet.org
ns4.byet.org
ns5.byet.org
The nameservers are changed via your domain registrar
[in our case Network Solutions] control panel, NOT your
hosting control panel [in our case
domainsforauthors.com].
With free domainsforauthors account name servers
MUST be set first, before adding the domain here in
control panel.
After ___ hours http://studentdemo.org now pointa to the web site
hosted at domainforauthors.com
For SEO reasons previously discussed you should stop using the
original URL in this case
Use http://studentdemo.org
Stop using
http://demo.domainsforauthors.com
Insert screen shot of classdemo.org