Помогите пожалуйста после нажатия кнопки submit должен создаватся текстовый файл config.txt и даные которые были записаны в текстовые поля должны выводиться в текстовый файл. У меня выводит такие ошибки после которых создается текстовый файл сразу же после запуска сайта и туда ничего не записует а после нажатия submit сайт оновляется и выводит The file config.txt exists Notice: Undefined index: profile in /storage/ssd5/542/7426542/public_html/index.php on line 13 Notice: Undefined index: userpic in /storage/ssd5/542/7426542/public_html/index.php on line 14 Пользуюсь беспланым хостом www.000webhost.com Код файла index.php PHP: <?php require('top_template.inc'); $file = 'config.txt'; if (file_exists($file)) { echo "The file $file exists"; } else { require('form.inc'); } $tar1=$_POST['profile']; $tar2=$_POST["userpic"]; $fp = fopen("config.txt","w"); fwrite($fp,"\n $tar1:$tar2 \n"); fclose($fp); require('bottom_template.inc'); ?> Код файла form.inc HTML: <form action="index.php" method="post"> <p>Шлях до профіля користувача: <input type="text" name = "profile" ></p> <p>Шлях до юсерпіку користувача: <input type="text" name = "userpic" ></p> <p><input type="submit" /></p> </form> Код файла top_template.inc HTML: html> <head> <title>PHP</title> </head> <body> <h1 align='center'>PHP</h1> Код файла bottom_template.inc HTML: <br/> <hr size='2'/> <p align='center'> <font size='1'> Copyright (c) 2018 Serega356 </font> </body> </html>
PHP говорит тебе, что при первом пуске $_POST['profile'] и $_POST["userpic"] неопределены, что впринципе то и логично, так как POST запроса не было. Ты как минимум должен обернуть этот код в isset, тогда в этой части Notice`ов не будет. Код (Text): $tar1=$_POST['profile']; $tar2=$_POST["userpic"]; $fp = fopen("config.txt","w"); fwrite($fp,"\n $tar1:$tar2 \n"); fclose($fp);