-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe5ce92
commit 3198d09
Showing
10 changed files
with
183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php include 'menu.php'; ?> | ||
<h1>Php Array</h1> | ||
<?php | ||
$asiakkaat=array( | ||
array("en"=>'Mikko',"sn"=>'Virtanen'), | ||
array("en"=>'Liisa',"sn"=>'Virta'), | ||
array("en"=>'Jussi',"sn"=>'Jokinen'), | ||
array("en"=>'Aino',"sn"=>'Järvinen') | ||
); | ||
echo "<h2>Print_r</h2>"; | ||
print_r($asiakkaat); | ||
?> | ||
<h2>Tulostus foreach-loopilla</h2> | ||
<?php | ||
ini_set('display_errors', 1); | ||
foreach ($asiakkaat as $rivi) { | ||
echo 'Etunimi '.$rivi['en'].' Sukunimi '.$rivi['sn'].'<br>'; | ||
} | ||
?> | ||
<h2>Tulostus taulukkona</h2> | ||
<TABLE border=2> | ||
<TR><TH>Etunimi</TH><TH>Sukunimi</TH></TR> | ||
<?php | ||
foreach ($asiakkaat as $rivi) { | ||
echo '<tr><td>'.$rivi['en'].'</td><td>'.$rivi['sn'].'</td></tr>'; | ||
} | ||
?> | ||
</TABLE> | ||
|
||
<?php include 'footer.php'; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php include "menu.php";?> | ||
<h1>Asiakkaat</h1> | ||
<?php | ||
include "yhteys.php"; | ||
$sql="SELECT etunimi,sukunimi FROM asiakkaat"; | ||
//echo $sql; | ||
$asiakkaat=$db->query($sql); | ||
echo "<TABLE border=1>"; | ||
echo "<TR><TH>Etunimi</TH><TH>Sukunimi</TH></TR>"; | ||
foreach ($asiakkaat as $rivi) { | ||
echo '<tr><td>'.$rivi['etunimi'].'</td><td>'.$rivi['sukunimi'].'</td></tr>'; | ||
} | ||
echo "</TABLE>"; | ||
|
||
?> | ||
|
||
<?php include "footer.php";?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
</div> | ||
<hr> | ||
Pekka Alaluukas 2016 | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php include 'menu.php'; ?> | ||
<h1>Testataan get-metodia</h1> | ||
|
||
<form method="get" action="get.php"> | ||
<label>Etunimi</label> | ||
<input type="text" name="en" required=""> | ||
<br> | ||
<label>Sukunimi</label> | ||
<input type="text" name="sn" required=""> | ||
<br> | ||
<input type="submit" name="nappi" value="Lähetä"> | ||
</form> | ||
|
||
<?php | ||
if(isset($_GET['nappi'])) { | ||
$enimi=$_GET['en']; | ||
$snimi=$_GET['sn']; | ||
echo "Terve $enimi $snimi"; | ||
} | ||
?> | ||
|
||
<?php include 'footer.php'; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php include "menu.php" ?> | ||
|
||
<h1>Esimerkki2</h1> | ||
<p> | ||
Tällä sivustolla on harjoiteltu php-ohjelmointia ja | ||
css-tiedoston käyttöä. | ||
</p> | ||
<p> | ||
Tiedostoa yhteys.php ei pitäisi viedä githubiin, jos kyseessä olisi oikea sovellus. | ||
Nythän käytämme public-tyyppistä git-repositoryä, joka on siis kaikkien luettavissa. | ||
Ja koska, tuossa yhteys-tiedostossa on tietokannan salasana, se kannattaisi siis | ||
poistaa Git-hubista. Ja sitten kannattaisi tehdä .gitignore tiedosto ja merkitä sinne tuo "yhteys.php". | ||
</p> | ||
|
||
<?php include "footer.php" ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Esimerkki2</title> | ||
<link rel="stylesheet" type="text/css" href="tyyli.css"> | ||
</head> | ||
<body> | ||
<div id="menu"> | ||
<ul> | ||
<li>Valikko</li> | ||
<li><a href="index.php">Etusivu</a></li> | ||
<li><a href="post.php">Post lomake</a></li> | ||
<li><a href="get.php">Get lomake</a></li> | ||
<li><a href="array.php">Array</a></li> | ||
<li><a href="asiakas.php">Asiakkaat</a></li> | ||
<li><a href="sql.php">SQL-koodi</a></li> | ||
</ul> | ||
</div> | ||
<div id="sisalto"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php include 'menu.php'; ?> | ||
<h1>Testataan post-metodia</h1> | ||
<form method="post" action="post.php"> | ||
<label>Etunimi</label> | ||
<input type="text" name="en" required=""> | ||
<br> | ||
<label>Sukunimi</label> | ||
<input type="text" name="sn" required=""> | ||
<br> | ||
<input type="submit" name="nappi" value="Lähetä"> | ||
</form> | ||
|
||
<?php | ||
if(isset($_POST['nappi'])) { | ||
$enimi=$_POST['en']; | ||
$snimi=$_POST['sn']; | ||
echo "Terve $enimi $snimi"; | ||
} | ||
?> | ||
|
||
<?php include 'footer.php'; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php include "menu.php";?> | ||
<pre> | ||
CREATE DATABASE esim2 DEFAULT CHARSET=utf8 COLLATE=utf8_swedish_ci; | ||
|
||
USE esim2; | ||
|
||
CREATE TABLE asiakkaat ( | ||
id_asiakas INT primary key auto_increment, | ||
etunimi VARCHAR(50), | ||
sukunimi VARCHAR(50) | ||
); | ||
|
||
|
||
INSERT INTO asiakkaat (etunimi,sukunimi) VALUES('Matti','Virtanen'); | ||
INSERT INTO asiakkaat (etunimi,sukunimi) VALUES('Jussi','Virta'); | ||
INSERT INTO asiakkaat (etunimi,sukunimi) VALUES('Liisa','Joki'); | ||
INSERT INTO asiakkaat (etunimi,sukunimi) VALUES('Aino','Järvinen'); | ||
|
||
GRANT ALL ON esim2.* TO 'phpuser'@'localhost' IDENTIFIED BY 'phppass'; | ||
|
||
</pre> | ||
<?php include "footer.php";?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
label { | ||
color: blue; | ||
} | ||
|
||
#menu { | ||
float: left; | ||
width: 150px; | ||
background-color: gray; | ||
} | ||
#menu ul { | ||
list-style: none; | ||
} | ||
#menu ul a:hover { | ||
background-color: white; | ||
} | ||
|
||
#sisalto { | ||
margin-left: 170px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
$palvelin="mysql:host=localhost; dbname=esim2"; | ||
try { | ||
$db=new PDO($palvelin,"phpuser","phppass"); | ||
//echo "Yhteys OK"; | ||
|
||
} catch (Exception $e) { | ||
echo "Tietokantaan ei saatu yhteyttä, ota yhteys ylläpitoon"; | ||
|
||
} | ||
|
||
|
||
?> |