Я все еще новичок в html и PHP в целом. Я работаю над сайтом, посвященным игровым новостям, который включает раздел комментариев, в котором люди могут комментировать новости. Я сделал комментарий PHP, в котором я упростил большую часть кода, чтобы не повторять его, следуя принципу DRY. Мне было интересно, есть ли способ изменить часть файла PHP в другой файл PHP? В приведенном ниже коде у меня есть 2 части, одна из которых находится в файле комментария. php, а другой код включен. php сайтов, на которых я хочу, чтобы комментарии были доступны. Я хочу изменить, к какому запросу я ВСТАВЛЯЮ & ВЫБРАТЬ * ИЗ ТОКА, что в данный момент это commentsxcom, и я хочу изменить его на commentsvalorant et c. Есть ли способ для меня сделать это?
function commentInput(){
//echo "test";
if(isset($_POST['submitComment'])){
//echo "submittest";
$user = $_POST['user'];
$date = $_POST['date'];
$message = $_POST['message'];
//Inserts data in sql
$sql = "INSERT INTO commentsxcom(user, date, message) VALUES('$user', '$date', '$message')";
global $conn;
$result = $conn ->query($sql);
}
}
//Retrives data from SQL
function getComments($conn){
$sql = "SELECT * FROM commentsxcom";
$result = $conn->quary($sql);
while($echoarray = $result->fetch_assoc()){
//Fetch will get the different results from the databases it will then insert them into arrays which I can echo
echo"<div class='comment-container'>";
echo $echoarray['user'];
echo $echoarray['date'];
echo $echoarray['message'];
echo"</div>";
}//End of while
}
?>
//This is the code where I want to change the commentsxcom to another sql quary
<?php
echo "
<form method='POST' action='".commentInput($conn)."'>
<input type='hidden' name='user' value='Anonymous'>
<input type='hidden' name='date' value='".date('Y-m-d H:i:s')."'>
<textarea name='message'></textarea>
<br>
<button name='submitComment' type='submit' class='buttoncomments'>Comment</button>
</form>
";
getComments($conn);
?>
</div>
```strong text