in.php

 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
define('SMARTY_DIR', './smarty/');
require_once(SMARTY_DIR. 'Smarty.class.php');
session_start();
$smarty = new Smarty();
$result_arr = array();
mysql_connect('localhost', 'root', '');
mysql_select_db('Track');
$smarty -> assign('title', 'Tracktors');
mysql_query ("set character_set_client='cp1251'");
mysql_query ("set character_set_results='cp1251'");
mysql_query ("set collation_connection='cp1251_general_ci'");
if ((isset($_GET['action'])) && ($_GET['action'] == 'view')) {
$smarty->assign('view', '1');
$sql = 'SELECT * FROM Tracktors';
$result = mysql_query($sql);
$i = 0;
while ($tempArr = mysql_fetch_array($result))
$result_sm[$i++] = $tempArr['id']. ') '. 'name: '.$tempArr['name'].'.';
$smarty->assign('view_arr', $result_sm);
}
elseif (isset($_POST['name'])) {
echo $sql = 'INSERT INTO Tracktors ( name, corp, country, year, dealer, ch) VALUES ( "'.$_POST['name'].'", "'.$_POST['corp'].'", "'.$_POST['country'].'", '.$_POST['year'].', "'.$_POST['dealer'].'", "'.$_POST['ch'].'")';
mysql_query($sql);
}
else {
$result_arr[0]['title'] = 'Название';
$result_arr[0]['name'] = 'name';
$result_arr[0]['id'] = 'name';
$result_arr[0]['type'] = 'text';
$result_arr[0]['reg'] = '[A-Za-zА-Яа-я]+';
$result_arr[1]['title'] = 'Корпорация';
$result_arr[1]['name'] = 'corp';
$result_arr[1]['id'] = 'corp';
$result_arr[1]['type'] = 'text';
$result_arr[1]['reg'] = '[A-Za-zА-Яа-я]+';
$result_arr[2]['title'] = 'Страна';
$result_arr[2]['name'] = 'country';
$result_arr[2]['id'] = 'country';
$result_arr[2]['type'] = 'text';
$result_arr[2]['reg'] = '[A-Za-zА-Яа-я]+';
$result_arr[3]['title'] = 'Год выпуска';
$result_arr[3]['name'] = 'year';
$result_arr[3]['id'] = 'year';
$result_arr[3]['type'] = 'text';
$result_arr[3]['reg'] = '[0-9]';
$result_arr[4]['title'] = 'Поставщик';
$result_arr[4]['name'] = 'dealer';
$result_arr[4]['id'] = 'dealer';
$result_arr[4]['type'] = 'text';
$result_arr[4]['reg'] = '[A-Za-zА-Яа-я]';
$result_arr[5]['title'] = 'Ответственный';
$result_arr[5]['name'] = 'ch';
$result_arr[5]['id'] = 'ch';
$result_arr[5]['type'] = 'text';
$result_arr[5]['reg'] = '[A-Za-zА-Яа-я]';
}
echo '<form action="show.php" method="post">';
echo '<input name="goToEdit" type="submit" value="&#1056;&#1077;&#1076;&#1072;&#1082;&#1090;&#1080;&#1088;&#1086;&#1074;&#1072;&#1090;&#1100;">';
echo '</form>';
$smarty -> assign('mark', $result_arr);
$_SESSION['n'] = $_SESSION['n'] + 1;
$smarty -> assign('n',$_SESSION['n']);
$smarty -> display('tpl.html');
?>