Hello everybody. There is a form and a script that add the entered information to the database. How can I add the function of uploading a file to the server to this code, and write its relative path to the database in the img field of the news table, so that the link would be "/img/news/%filename%.jpg"
<form action="save_news.php" method="post" name="news"> <table border="1" cellpadding="0" cellspacing="0" width="350"> <tr> <td colspan="2" align="center" height="50px"><strong>Отправка запроса</strong></td> </tr> <tr> <td width="150" height="50px" align=center>Тема новости :</td> <td align=center><input type="text" name="title" maxlength="30" /></td> </tr> <tr> <td width="150" height="50px" align=center>Текст новости :</td> <td align=center><textarea name="text"></textarea></td> </tr> <tr> <td width="150" height="50px" align=center>Автор новости :</td> <td align=center><input type="text" name="author" maxlength="30" /></td> </tr> <tr> <td width="150" height="50px" align=center>Изображение новости:</td> <td align=center><input type="text" name="img" /></td> </tr> <tr> <td colspan="2" align="center" height="50px"> <input type="submit" class="buttons" value="Отправить запрос" /> <input type="reset" class="buttons" value="Очистить" /> </td> </tr> </table> </form> <? include('../script/config.php'); $cdate = date("Ymd"); $query = "INSERT INTO news SET title='".$_POST['title']."', text='".$_POST["text"]."', author='".$_POST["author"]."',date='$cdate', img=".$_POST["img"].""; } mysql_query($query) or die(mysql_error()); mysql_close(); echo ("<div style=\"text-align: center; margin-top: 10px;\"> <font color=\"green\">Данные успешно сохранены!</font> <a href=\"news.php\">Вернуться назад</a></div>"); ?>