Skip to content

Commit ab4fe8e

Browse files
committed
php add pizza
1 parent a30cf35 commit ab4fe8e

File tree

4 files changed

+73
-19
lines changed

4 files changed

+73
-19
lines changed

add.php

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
<?php
22
include('../tuto/config/db_connect.php');
33

4+
if(isset($_POST['submit'])) {
5+
session_start();
6+
7+
setcookie('title', $_POST['title'], time() + 86400);
8+
setcookie('email', $_POST['email'], time() + 86400);
9+
setcookie('ingredients', $_POST['ingredients'], time() + 86400);
10+
$titleCookie = $_COOKIE['title'] ?? 'unknow';
11+
$emailCookie = $_COOKIE['email'] ?? 'unknow';
12+
$ingredientsCookie = $_COOKIE['ingredients'] ?? 'unknow';
13+
14+
15+
16+
}
417
$title = $email = $ingredients = '';
518
$errors = array('email'=> '', 'title' => '', 'ingredients' => '');
619

@@ -53,8 +66,8 @@
5366
echo 'query error' . mysqli_error($conn);
5467
}
5568
mysqli_close($conn);
56-
$errors['formvalid'] = '<div class="btn green">form is send, redirect to index after 5 secondes</div><br />';
57-
header( "refresh:5;url=index.php" );
69+
$errors['formvalid'] = '<div class="btn green">form is sen</div><br />';
70+
5871
}
5972
}
6073
}
@@ -67,7 +80,7 @@
6780
<h4 class="center">add a pizza
6881

6982
</h4>
70-
<form action="" class="white" action="add.php" method="POST">
83+
<form class="white" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
7184
<label for="">your mail:</label>
7285

7386
<input type="text" name="email" value="<?php echo htmlspecialchars( $email) ?>" >
@@ -85,6 +98,32 @@
8598
<input type="submit" name="submit" value="btn" class="btn brand z-depth-0">
8699
</div>
87100
</form>
101+
102+
103+
<div class="container">
104+
<div class="row">
105+
<h4>Your Pizza</h4>
106+
<div class="col s6 md3">
107+
<div class="card z-depth-0">
108+
<img src="./img/pizza.jpg" class="pizza">
109+
<div class="card-content center">
110+
<h6><?php echo $titleCookie ?></h6>
111+
<ul>
112+
<?php foreach(explode(',', $ingredientsCookie) as $ing): ?>
113+
<li class='btn green m4'><?php echo htmlspecialchars( $ing); ?></li><br />
114+
<?php endforeach ?>
115+
</ul>
116+
</div>
117+
<div class="card-action right-align">
118+
write by <?php echo $emailCookie ?>
119+
</div>
120+
</div>
121+
</div>
122+
123+
124+
125+
</div>
126+
</div>
88127
</section>
89128
<?php include('templates/footer.php')?>
90129

index.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
<!DOCTYPE html>
1919
<html lang="en">
20-
<?php include('templates/header.php')?>
20+
<?php include('templates/header.php')?>
21+
2122
<h4 class="center grey-text">pizza!</h4>
2223
<div class="container">
2324
<div class="row">

sandbox.php

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
<?php
2-
$score = 50;
2+
class user {
3+
public $email;
4+
public $name;
35

4-
$score > 40 ? 'high score' : 'low score';
5-
?>
6+
public function __construct($name, $email)
7+
{
8+
$this->email = $email;
9+
$this->name = $name;
10+
11+
}
12+
public function login(){
13+
echo $this->name . 'user are log';
14+
}
15+
}
16+
// $userOne = new User();
617

7-
<!DOCTYPE html>
8-
<html lang="en">
9-
<head>
10-
<meta charset="UTF-8">
11-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
12-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
13-
<title>Document</title>
14-
</head>
15-
<body>
16-
17-
</body>
18-
</html>
18+
// $userOne->login();
19+
// echo $userOne->name . '<br />';
20+
// echo $userOne->email ;
21+
$userTwo = new User('john', '[email protected]');
22+
echo $userTwo-> login();
23+
?>

templates/header.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
<?php
2+
session_start();
3+
if($_SERVER['query_string'] == 'noname'){
4+
unset($_SESSION['name']);
5+
}
6+
$name = $_SESSION['name'] ?? 'Guest';
7+
$gender = $_COOKIE['gender'] ?? 'unknow';
8+
?>
19
<head>
210
<meta charset="UTF-8">
311
<meta http-equiv="X-UA-Compatible" content="IE=edge">
@@ -31,6 +39,7 @@
3139
<div class="container">
3240
<a href="index.php" class="brand-logo brand-text">Ninja pizza</a>
3341
<ul id="nav-mobile" class="right hide-on-small-and-down">
42+
<li class="grey-text">hello<?php echo htmlspecialchars($name)?>(<?php echo htmlspecialchars($gender)?>)</li>
3443
<li><a href="add.php" class="btn brand z-depth-0">add a pizza</a></li>
3544
</ul>
3645
</div>

0 commit comments

Comments
 (0)