-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaltaOrder.php
More file actions
39 lines (30 loc) · 854 Bytes
/
altaOrder.php
File metadata and controls
39 lines (30 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
if(isset($_POST['ok'])){
//Incluyendo
require_once('./classes/Order.class.php');
//Guardando del formulario
$name = $_POST['product'];
$price = intval($_POST['price']);
//Creando el objeto
$order = new Order($name, $price);
//De objeto a json
$orderjson = json_encode($order, JSON_PRETTY_PRINT);
//Guardar información en un archivo
$file = __DIR__ . "/order.json";
if(!file_exists($file)){
$file = fopen($file, "w");
fwrite($file, "[\n");
}else{
$file = fopen($file, "c");
fseek($file, -2, SEEK_END);
fwrite($file, ",\n");
}
fwrite($file, $orderjson);
fwrite($file, "\n]");
fclose($file);
header("refresh:0; url='main.php'");
}else{
echo "<h1 style=color:red;>No</h1>";
header("refresh:3; url='index.php");
}
?>