hl.strana
<? session_start();
$server = "sdatabase";
$login = "";
$heslo = "";
$databaze = "";
$spojeni = mysqli_connect($server, $login, $heslo, $databaze);
if (mysqli_error($spojeni)) {
echo "Chyba: ".mysqli_error();
die("Smůla!");
}
mysqli_query($spojeni, "SET NAMES 'utf8'");
?>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
<head><!-- ščřžýŠČŘŽÝ -->
<meta name="generator" content="PSPad editor, www.pspad.com" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" rel="nofollow" href="styl.css" type="text/css">
</head>
<body>
<div id="all">
<div id="hlava">
<div id="login">
<?php
if (isset($_POST['login'])) {
$jmeno = $_POST['jmeno'];
$heslo = $_POST['heslo'];
$log = "user";
if ($jmeno == $log && $heslo == $log) {
echo '<p><a rel="nofollow" href="/?stranka=2">Dokončit</a></p>';
}
} else {
echo "<h1>Login</h1>";
include ('login_form.inc.php');
}
?>
</div>
</div>
<div id="telo">
<div id="nav">
<ul>
<li><a rel="nofollow" href="/?stranka=1">Objednavky</a></li>
</div>
<div id="obsah">
<table>
<tr><td>auto</td><td><input type="checkbox" name="auto" value="1"></td><td>Cena: 100000</td></tr>
<tr><td>mobil</td><td><input type="checkbox" name="mobil" value="2"></td><td>Cena: 10000</td></tr>
<tr><td>tablet</td><td><input type="checkbox" name="tablet" value="3"><td>Cena: 5000</td></td></tr>
<tr><td>pc</td><td><input type="checkbox" name="pc" value="4"></td><td>Cena: 50000</td></tr>
</table>
<?php
if (isset($_GET['stranka'])) {
if ($_GET['stranka'] == 1) {
echo "Objednávky";
include "vypis.inc.php";
} elseif ($_GET['stranka'] == 2) {
echo "Vypln";
include "pridej_form.inc.php";
} elseif ($_GET['stranka'] == 3) {
echo "Souhrn";
include "";
}else {
echo "Neexistuje";
}
}
?>
</div>
</div>
</div>
</body>
</html>
Logování
<?php
if (isset($_POST['login'])) {
$jmeno = $_POST['jmeno'];
$heslo = $_POST['heslo'];
$log = "user";
if ($jmeno == $log && $heslo == $log) {
$_SESSION['prihlasen'] = 1;
$_SESSION['jmeno'] = "user";
}
}
} elseif (isset($_GET['akce']) && $_GET['akce'] == "odhlasit") {
//session_unset();
//session_destroy();
unset($_SESSION['prihlasen']);
unset($_SESSION['jmeno']);
}
?>
Formulář logování
<form action="/" method="post">
<table>
<tr><td>Jméno:</td><td><input type="text" name="jmeno"></td></tr>
<tr><td>Heslo:</td><td><input type="password" name="heslo"></td></tr>
<tr><td></td><td><input type="submit" name="login" value="Přihlásit"></td></tr>
</table>
</form>
Vložení
<?php
if(isset($_POST['odeslat'])){
$jmeno = $_POST["jmeno"];
$prijmeni = $_POST["prijmeni"];
if (isset($_POST['auto'])){
$insert = "INSERT INTO objednavky VALUES ('$jmeno', '$prijemni', 'auto', '100000');";
$vysledek = mysqli_query($spojeni, $insert);
}
if (isset($_POST['mobil'])){
$insert2 = "INSERT INTO objednavky VALUES ('$jmeno', '$prijemni', 'mobil', '10000');";
$vysledek = mysqli_query($spojeni, $insert2);
}
if (isset($_POST['tablet'])){
$insert3 = "INSERT INTO objednavky VALUES ('$jmeno', '$prijemni', '$tablet', '5000');";
$vysledek = mysqli_query($spojeni, $insert3);
}
if (isset($_POST['pc'])){
$insert4 = "INSERT INTO objednavky VALUES ('$jmeno', '$prijemni', '$pc', '50000');";
$vysledek = mysqli_query($spojeni, $insert4);
}
}
?>
<form action="index.php/" method="post">
<table>
<tr><td>Jméno:</td><td><input type="text" name="jmeno"></td></tr>
<tr><td>Přijmeni:</td><td><input type="text" name="prijmeni"></td></tr>
<tr><td>Adresa:</td><td><textarea rows="5" cols="20"></textarea></td></tr>
<tr><td></td><td><input type="submit" name="odeslat" value="Odeslat"></td></tr>
</table>
</form>
Výpis
<?php
$vysledek = mysqli_query($spojeni, "SELECT * FROM objednavky");
echo "<table>
<th>Jmeno</th>
<th>Prijmeni</th>
<th>zbozi</th>
<th>cena</th>
";
while ($radek = mysqli_fetch_array($vysledek)) {
echo "<tr>";
echo '<td>'.$radek['jmeno'].'</td>';
echo '<td>'.$radek['prijmeni'].'</td>';
echo '<td>'.$radek['zbozi'].'</td>';
echo '<td>'.$radek['cena'].'</td>';
echo "</tr>";
}
echo "</table>";
?>