Help: convert code for PHPRad Classic

Limit the number of records users can add

First of all I apologize for my little experience with PHP, but I need help to convert the code below into an event for PHPRad Classic.

What this code does: It limits the number of posts based on the limit set in the database, in the user table.

In short, it is to create a limit on the number of posts, whether it is a post or any other information.

I know I have to add it on the winds page, in the option before adding.

if you have a simpler way to do the same action, no problem.
if it’s not asking too much, add the option to redirect to a specific url.

$rs = DB::Query("select count(*) as c from ads where userid = " . $_SESSION["UserID"]);
$data = $rs.fetchAssoc();
$count = $data["c"];
$rs2 = DB::Query("select ".AddFieldWrappers( "userlimit" )." from users where userid = " . $_SESSION["UserID"]);
$data2 = $rs2.fetchAssoc();
$limit = $data2["userlimit"];
if ($count>= $limit)
  echo "Limit reached: $count records added already";

your code is okay the way it is.