Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php session_start();?>
- <?php require_once("libs.php");?>
- <?php require_once("conec.php");?>
- <?php
- if($_POST['submit']){
- $name =trim(mysql_real_escape_string( $_POST['name']));
- $phone =trim(mysql_real_escape_string( $_POST['phone']));
- $age =trim((int)$_POST['age']);
- $error = '';
- if(empty($name)) $error .= "<p>Не заполнено Имя</p>";
- if(empty($phone)) $error .= "<p>Не заполнено Телефон</p>";
- if(empty($age)) $error .= "<p>Не заполнено Возраст</p>";
- if(empty($error)) {
- if (newContact($name, $phone, $age)){
- $_SESSION['res'] = '<p>ДОБАВЛЕННО</p>';
- header("Location: new.php");
- exit;
- }else{
- $_SESSION['res'] = '<p>ОШИБКА</p>';
- header("Location: new.php");
- exit;
- }
- }else{
- $_SESSION['res'] = $error;
- header("Location: new.php");
- exit;
- }
- }
- ?>
- <?php require_once("menu.php");?>
- <form action="" method="post">
- <p>Имя*: <input type="text" name"name"></p>
- <p>Телефон: <input type="text" name"phone"></p>
- <p>Возраст: <input type="text" name"age"></p>
- <p><input type="submit" value="Добавить"></p>
- </form>
- <?= $_SESSION['res'];
- session_unset();
- session_destroy();
- ?>
- 2й фал либс
- <?php
- // показ абонентов
- function showAll() {
- $query = "select * from test";
- $res = mysql_query($query);
- $data = array();
- while($row = mysql_fetch_assoc($res)) {
- $data[] = $row;
- }
- return $data;
- }
- //..Добавление абонента
- function newContact($name, $phone, $age) {
- $query = "insert into test (name, phone, age) VALUES ('$name', '$phone', $age)";
- $res = mysql_query($query);
- if( mysql_affected_rows() > 0) {
- return true;
- }else{
- return false;
- }
- }
- ?>
- 3й файл показа
- <?php
- // показ абонентов
- function showAll() {
- $query = "select * from test";
- $res = mysql_query($query);
- $data = array();
- while($row = mysql_fetch_assoc($res)) {
- $data[] = $row;
- }
- return $data;
- }
- //..Добавление абонента
- function newContact($name, $phone, $age) {
- $query = "insert into test (name, phone, age) VALUES ('$name', '$phone', $age)";
- $res = mysql_query($query);
- if( mysql_affected_rows() > 0) {
- return true;
- }else{
- return false;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement