Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. <?php session_start();?>
  2. <?php require_once("libs.php");?>
  3. <?php require_once("conec.php");?>
  4. <?php
  5. if($_POST['submit']){
  6. $name =trim(mysql_real_escape_string( $_POST['name']));
  7. $phone =trim(mysql_real_escape_string( $_POST['phone']));
  8. $age =trim((int)$_POST['age']);
  9. $error = '';
  10. if(empty($name)) $error .= "<p>Не заполнено Имя</p>";
  11. if(empty($phone)) $error .= "<p>Не заполнено Телефон</p>";
  12. if(empty($age)) $error .= "<p>Не заполнено Возраст</p>";
  13. if(empty($error)) {
  14. if (newContact($name, $phone, $age)){
  15. $_SESSION['res'] = '<p>ДОБАВЛЕННО</p>';
  16. header("Location: new.php");
  17. exit;
  18. }else{
  19. $_SESSION['res'] = '<p>ОШИБКА</p>';
  20. header("Location: new.php");
  21. exit;
  22. }
  23. }else{
  24. $_SESSION['res'] = $error;
  25. header("Location: new.php");
  26. exit;
  27. }
  28. }
  29. ?>
  30. <?php require_once("menu.php");?>
  31. <form action="" method="post">
  32. <p>Имя*: <input type="text" name"name"></p>
  33. <p>Телефон: <input type="text" name"phone"></p>
  34. <p>Возраст: <input type="text" name"age"></p>
  35. <p><input type="submit" value="Добавить"></p>
  36. </form>
  37. <?= $_SESSION['res'];
  38. session_unset();
  39. session_destroy();
  40. ?>
  41.  
  42. 2й фал либс
  43.  
  44. <?php
  45. // показ абонентов
  46. function showAll() {
  47. $query = "select * from test";
  48. $res = mysql_query($query);
  49. $data = array();
  50. while($row = mysql_fetch_assoc($res)) {
  51. $data[] = $row;
  52. }
  53. return $data;
  54. }
  55. //..Добавление абонента
  56. function newContact($name, $phone, $age) {
  57. $query = "insert into test (name, phone, age) VALUES ('$name', '$phone', $age)";
  58. $res = mysql_query($query);
  59. if( mysql_affected_rows() > 0) {
  60. return true;
  61. }else{
  62. return false;
  63. }
  64. }
  65. ?>
  66.  
  67. 3й файл показа
  68.  
  69. <?php
  70. // показ абонентов
  71. function showAll() {
  72. $query = "select * from test";
  73. $res = mysql_query($query);
  74. $data = array();
  75. while($row = mysql_fetch_assoc($res)) {
  76. $data[] = $row;
  77. }
  78. return $data;
  79. }
  80. //..Добавление абонента
  81. function newContact($name, $phone, $age) {
  82. $query = "insert into test (name, phone, age) VALUES ('$name', '$phone', $age)";
  83. $res = mysql_query($query);
  84. if( mysql_affected_rows() > 0) {
  85. return true;
  86. }else{
  87. return false;
  88. }
  89. }
  90. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement