За последние 24 часа нас посетили 22514 программистов и 1188 роботов. Сейчас ищут 763 программиста ...

показывпет пустой экран почекму

Тема в разделе "PHP для новичков", создана пользователем riaron, 11 июл 2020.

  1. riaron

    riaron Активный пользователь

    С нами с:
    1 окт 2014
    Сообщения:
    247
    Симпатии:
    4
    PHP:
    1. <?php
    2. abstract class abstra{
    3. public $user_id;
    4. public $id;
    5. public $phone;
    6. abstract public function input();
    7. abstract public function inputd();
    8. abstract public function inputs();
    9. abstract public function show();
    10. abstract public function add($user_id, $phone);
    11. abstract public function dell($id);
    12. abstract public function search($user_id);
    13.  
    14. }
    15. class positions extends abstra{
    16.     public $user_id;    
    17.     public $id;
    18.     public $phone;
    19. function __construct(){
    20.      $this->submit = filter_input(INPUT_POST, 'submit');
    21.      $this->submitd = filter_input(INPUT_POST, 'submitd');
    22.      $this->submits = filter_input(INPUT_POST, 'submits');
    23.         $this->user_id = filter_input(INPUT_POST, 'user_id');
    24.         $this->phone = filter_input(INPUT_POST, 'phone');
    25.         if(isset($this->submitd)){
    26.             $this->id = filter_input(INPUT_POST, 'user_id');
    27.  
    28.         }
    29. }
    30.     function input(){
    31.         echo"
    32.        <form method='POST'>
    33.            <table>
    34.                <tr>
    35.                    <td>User_Id</td>
    36.                    <td><input name='user_id' type='text' required></td>
    37.                </tr>
    38.                <tr>
    39.                    <td>Phone</td>
    40.                    <td><input name='phone' type='text'  required></td>
    41.                </tr>
    42.                <tr>
    43.                    <td><input name='submit' type='submit'></td>
    44.                    <td></td>
    45.                </tr>
    46.            </table>
    47.        </form>";
    48.     }      
    49.     function inputd(){
    50.         echo"
    51.        <form method='POST'>
    52.            <table>
    53.                <tr>
    54.                    <td>User_Id</td>
    55.                    <td><input name='user_id' type='text' required></td>
    56.                </tr>
    57.                <tr>
    58.                    <td><input name='submitd' type='submitd'></td>
    59.                    <td></td>
    60.                </tr>
    61.            </table>
    62.        </form>";
    63.     }     function inputs(){
    64.         echo"
    65.        <form method='POST'>
    66.            <table>
    67.                <tr>
    68.                    <td>User_Id</td>
    69.                    <td><input name='user_id' type='text' required></td>
    70.                </tr>
    71.                <tr>
    72.                    <td><input name='submitd' type='submits'></td>
    73.                    <td></td>
    74.                </tr>
    75.            </table>
    76.        </form>";
    77.     }  
    78.     function show(){
    79.         $mysqli = new mysqli('localhost', 'mysql','mysql', 'test');
    80.     $query = "SELECT count(1) FROM `phone_numbers`";
    81.     if ($stmt = $mysqli->prepare($query)) {
    82.         $stmt->execute();
    83.         $stmt->bind_result($counter);
    84.  
    85.         while ($stmt->fetch()) {
    86.             sprintf("%s", $counter);
    87.         }
    88.         $stmt->close();
    89.     }
    90.     $mysqli->close();
    91.     for($i=0;$i<$counter;$i++){
    92.         $mysqli = new mysqli('localhost', 'mysql','mysql', 'test');
    93.             $query = "SELECT `user_id`,`phone` FROM `phone_numbers` LIMIT ?,1";
    94.             if ($stmt = $mysqli->prepare($query)) {
    95.                 $stmt->bind_param("i", $i);
    96.                 $stmt->execute();
    97.                 $stmt->bind_result($user_id,$phone);
    98.                 while ($stmt->fetch()) {
    99.                     sprintf("%s (%s)\n", $user_id,$phone);
    100.                 }
    101.                 $stmt->close();
    102.             }
    103.             $mysqli->close();
    104.             echo "user_id: $user_id phone: $phone<br>";
    105.     }     }
    106.     function add($user_id,$phone){
    107.          $mysqli = new mysqli('localhost', 'mysql','mysql', 'test');
    108.         // Вытаскиваем из БД запись, у которой логин равняеться введенному
    109.         $query = "INSERT INTO `phone_numbers` `id`,`user_id`, `phone` VALUES (NULL, ?, ?);";
    110.         if ($stmt = $mysqli->prepare($query)) {
    111.             // Запустить выражение
    112.             $stmt->bind_param("ii",$user_id,$phone);
    113.             $stmt->execute();
    114.             $stmt->close();
    115.         }
    116.         // Закрыть соединение
    117.         $mysqli->close();
    118.  
    119.     }  
    120.     function dell($id){
    121.         $mysqli = new mysqli('localhost', 'mysql','mysql', 'test');
    122.     $query = "DELETE FROM `phone_numbers` where `id`=?";
    123.     if ($stmt = $mysqli->prepare($query)) {
    124.         $stmt->bind_param("i",$id);
    125.         $stmt->execute();
    126.         $stmt->bind_result($counter);
    127.  
    128.         while ($stmt->fetch()) {
    129.             sprintf("%s", $counter);
    130.         }
    131.         $stmt->close();
    132.     }
    133.     $mysqli->close();
    134.     }  
    135.     function search($user_id){
    136.         $mysqli = new mysqli('localhost', 'mysql','mysql', 'test');
    137.             $query = "SELECT user_id,phone FROM `phone_numbers` WHERE `user_id`";
    138.             if ($stmt = $mysqli->prepare($query)) {
    139.                 $stmt->bind_param("i", $user_id);
    140.                 $stmt->execute();
    141.                 $stmt->bind_result($user_id,$phone);
    142.                 while ($stmt->fetch()) {
    143.                     sprintf("%s (%s)\n", $user_id,$phone);
    144.                 }
    145.                 $stmt->close();
    146.             }
    147.         $mysqli->close();
    148.             echo "user_id: $user_id phone: $phone";
    149.     }  
    150. }
    151.  
    152. $positions=new positions;
    153. ?><div id="show"><?
    154. $positions->input;
    155. $positions->show;
    156. if(isset($positions->submit)){
    157.     $positions->add($positions->user_id,$positions->phone);
    158. }?>
    159. </div><div id="del"><?
    160. $positions->inputd;
    161. if(isset($positions->submitd)){
    162.     $positions->dell($positions->user_id);
    163. }
    164. ?>
    165. </div>
    166. <div id="search"><?
    167. $positions->inputd;
    168. if(isset($positions->submits)){
    169.     $positions->search($positions->user_id);
    170. }
     
    #1 riaron, 11 июл 2020
    Последнее редактирование: 11 июл 2020
  2. twim32

    twim32 Активный пользователь

    С нами с:
    29 мар 2017
    Сообщения:
    275
    Симпатии:
    58
    Хотите узнать что тут неправильно? Если кратко - всё. Но, это я так...

    Какие данные вы хотите увидеть, если вы их даже не отправляете? Для начала, вызовите хотя бы один метод, который выводит форму на экран, отправьте данные и посмотрите что происходит в вашем объекте с помощью функции var_dump()
     
  3. riaron

    riaron Активный пользователь

    С нами с:
    1 окт 2014
    Сообщения:
    247
    Симпатии:
    4
    а это что?
    PHP:
    1. $positions=new positions;
    2. ?><div id="show"><?
    3. $positions->input;
    4. $positions->show;
    5. if(isset($positions->submit)){
    6.     $positions->add($positions->user_id,$positions->phone);
    7. }?>
    8. </div><div id="del"><?
    9. $positions->inputd;
    10. if(isset($positions->submitd)){
    11.     $positions->dell($positions->user_id);
    12. }
    13. ?>
    14. </div>
    15. <div id="search"><?
    16. $positions->inputd;
    17. if(isset($positions->submits)){
    18.     $positions->search($positions->user_id);
    19. }
     
  4. twim32

    twim32 Активный пользователь

    С нами с:
    29 мар 2017
    Сообщения:
    275
    Симпатии:
    58
    Это кусок кода из первого поста в котором ничего не изменилось.

    Хорошо, давайте зайдём с другой стороны: ваш "супер объект" принимает данные из POST в конструкторе. Скажите, как вы собрались отправлять данные через POST без формы? Формы нет - и данных нет
     
  5. riaron

    riaron Активный пользователь

    С нами с:
    1 окт 2014
    Сообщения:
    247
    Симпатии:
    4
    С этим я разберусь, почему экран пустой?
     
  6. twim32

    twim32 Активный пользователь

    С нами с:
    29 мар 2017
    Сообщения:
    275
    Симпатии:
    58
  7. MouseZver

    MouseZver Суперстар

    С нами с:
    1 апр 2013
    Сообщения:
    7.752
    Симпатии:
    1.322
    Адрес:
    Лень
    не надо пихать классы ради классов. Пока Ролтон с холодной водой.
     
  8. riaron

    riaron Активный пользователь

    С нами с:
    1 окт 2014
    Сообщения:
    247
    Симпатии:
    4
    Я пишу тестовое задание
     
  9. riaron

    riaron Активный пользователь

    С нами с:
    1 окт 2014
    Сообщения:
    247
    Симпатии:
    4
    Забыл скобки после методов поставить
     
  10. MouseZver

    MouseZver Суперстар

    С нами с:
    1 апр 2013
    Сообщения:
    7.752
    Симпатии:
    1.322
    Адрес:
    Лень
    это оправдание ?

    тебе ответ был дан, см исход данные.
     
  11. Алекс8

    Алекс8 Активный пользователь

    С нами с:
    18 май 2017
    Сообщения:
    1.730
    Симпатии:
    359
    тогда не надо пихать html код в классы.. не место ему там.