0

I have this code - only because I can't figure out how to make it easier and nicer.

This code works and gets the job done. But I know that there is way better ways to get the same job done.

I'm looking into prepared statements, because I wan't to make the script and my website more secure. I don't know how to implement and convert code like this. I'm a visual guy, so I would like to have it shown.

    //GET FOLLOWERS OF THE THREAD
    $resultF = $con->query("SELECT 
        q_id,
        m_id
            FROM
        q_followers
            WHERE q_id = '".$q_id."'
    ");

    //COUNT NUMBER OF ROWS
    $row_cnt_F = $resultF->num_rows;

    //IF THERE IS FOLLOWERS - THEN INSERT A NOTIFICATION FOR EACH
    if($row_cnt_F > 0) {
        while($rowF = $resultF->fetch_assoc()){
            //INSERT NOTIFICATION
            $sqlF = "INSERT INTO notifications (n_type,m_id,timestamp)
            VALUES ('1','".$rowF['m_id']."','".$timestamp."')";
            mysqli_query($con, $sqlF);
        }
    }

Thank you.

Niels Hermann
  • 611
  • 2
  • 6
  • 13
  • 1
    Have a look into using "INSERT... SELECT...", it means you only have one statement and you don't have to mess around with loops/building queries etc. – Nigel Ren Mar 22 '18 at 11:10
  • Please provide your db file also. – PPL Mar 22 '18 at 11:33

0 Answers0