Yii2 functions from another php file

Hi! I am something of a noob, working on my first yii2 application and i am stuck.
In a module, i need to use some functions from another php file, one made by me. I am trying to create a comment section. (i made it outside of the application, but i don’t know how to reproduce it in the framework)

My echo and 99% of it’s content isn’t not showing in this question.

I need to use:

function setComments($conn) {
if (isset($_POST[‘commentSubmit’])){
$uid = $_POST[‘uid’];
$date = $_POST[‘date’];
$message = $_POST[‘message’];

  $sql = "INSERT INTO comments (uid, date, message) VALUES ('".$uid."', '".$date."', '".$message."')";
  $result = mysqli_query($conn, $sql);

}
}

I tried to use the include, require with namespace but i got an error. I couldn’t find a solution.

Based on what I see above I think you should not try to include such code. Read about PHP syntax a bit more, check framework docs then re-create what you did.

In the code above you’re giving any user ability to execute anything against your database.

Thank you for your answare! Indeed it’s a weakness, but this application will not see the web, it’s only a project that i want to use in my learning path. I am a bit frustrated, because i don’t know how to do that.

Okay then. Some links:

2 Likes

Thank you for the links and for your time! :smile: