I wrote the form code:

<form method='post' action='admin.php'> <table width='100%' style='color:white'> <tr><td>Категория:</td></tr> <tr> <td> <select name='category'> <option value='houses'>Участки</option> <option value='clothes'>Одежда</option> <option value='people'>Симы</option> <option value='animals'>Петы</option> <option value='others'>Разное</option> </select> </td> </tr> <tr><td>Название файла:</td><td><input type='text' name='name'></td></tr> <tr><td>Прямая ссылка на файл:</td><td><input type='text' name='link'></td></tr> <tr><td>Описание файла:</td><tr> <tr><td colspan='2'><textarea cols='50' rows='5' name='description'></textarea></td></tr> <tr><td>Скриншот:</td><tr> <tr><td><input type='file' name='image'></td><tr> <tr><td colspan='2'><center><input type='submit' value='Отправить' name='submit' class='button'></center></td></tr> </table> </form> 

Now in my select, each option has value = 'houses', etc. etc. Treatment...

 if (@$_POST['submit']) { $bd="bd/".$_POST['category'].".dat"; $name = $_POST['name']; $link = $_POST['link']; $description = $_POST['description']; $name = htmlspecialchars($name); $link = htmlspecialchars($link); $description = htmlspecialchars($description); if (!empty($name) && !empty($link) && !empty($message)) { $path = "images/fileimages/"; $tempfile = $_FILES['image']['tmp_name']; $newname = $path . "/" . $_FILES['image']['name']; $img = $_FILES['image']['name']; if (is_uploaded_file($tempfile)) { copy($tempfile, $newname); } $text = "$name:::$link:::$description:::$img"; $fh = fopen($bd, "a"); fwrite($fh, "$text\n"); fclose($fh); } } 

I need that when choosing from select , for example, “Sections”, the value of houses , etc., is written to $bd , but this does not happen, because nothing is added to the file. Help me please.

  • one
    @ivanforpw, To format the code, select it with the mouse and click on the button 101010 of the editor. - Nicolas Chabanovsky

1 answer 1

 $fh = fopen(filebd, "a"); 

change to

 $fh = fopen($filebd, "a"); 

And when writing data is better to serialize.

 $cat = $_POST['category']; //в твоем случае $bd $data = array('category' => $cat, 'name' => $name, 'link' => $link, 'desc' => $description, 'img' => $img); $write = serialize($data); $fh = fopen($filebd, "a"); fwrite($fh, $write); fclose($fh); 
  • I noticed about $ filebd already, changed it to $ bd, where $ bd = "bd /".$_ POST ['category'].". dat "; But the problem itself is in the transfer of the select, how from option to transfer the value of house or another and assign this value to $ bd in processing? - ivanforpw
  • I do not need to transfer the value of the select to a file, I need the value of the select to be equal to the value of the file name where this text is all and write, of course + .dat (format) - ivanforpw
  • $ filebd = 'bd /'.$ bd'.dat'; // If there is a bd directory $ fh = fopen ($ filebd, 'w'); - orine90
  • I did everything myself, just removed if (! empty ($ name) &&! empty ($ link) &&! empty ($ message)) {...};) - ivanforpw