PHP Add records to MYSQLI for all USERS

0

Good,

I'm tempted to, when making a Registry, this Registry add in all the example users.

users table

  id | username

Register to Add:

   id_users | movie_id | movie_name
   user1    |     ex2    |     ex2
   user2    |     ex2    |     ex2
   user3    |     ex2    |     ex2
   user4    |     ex2    |     ex2

I'm using this form ... Help.

              //$uploadOk = false;
          $titulo = $_POST['movie_serie'];
          $direct = $_POST['movie_dir'];

             $db_dir = "libraries/images/upload/".$direct.".jpg"; 

             //$query = mysqli_query($con, "INSERT INTO movies (movie_id, movie_name) VALUES ('$db_dir', '$titulo')");  

             $select = "SELECT username FROM users";
             $queryS = mysqli_query($con, $select);

                while($row = mysqli_fetch_array($queryS))
                { 
                     $u_array = array('username' => $row['username'], 'movie_id' => $_POST['movie_dir'], 'movie_name' => $_POST['movie_serie']); 

                     $query2 = mysqli_query($con, "INSERT INTO movies_notify (id_users, movie_id, movie_name) 
                     VALUES ($u_array)"); 

                }
    
asked by anonymous 13.08.2017 / 21:37

1 answer

1

This is my practice! , you should use mysqli prepared statements or PDO , so your application is vulnerable to various types of attacks!

The problem is that you were trying to convert an array to string .

while($row = mysqli_fetch_array($queryS))
{ 

     $query2 = mysqli_query($con, "INSERT INTO movies_notify (id_users, movie_id, movie_name) VALUES ('".$row['username']."','".$_POST['movie_dir']."','".$_POST['movie_serie']."')"); 

}
    
13.08.2017 / 22:18