PHP Add Records to MYSQLI for all USERS

Asked

Viewed 25 times

0

Good,

I am tempted that by making a Registration, that Register add in all example users.

table users

  id | username

Record 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)"); 

                }
  • If on the table movies_notify you must insert the id user, why you just select the username? And you can’t pass one array for the SQL statement, you will need to convert it to string.

1 answer

1

This is a practice! , you should wear mysqli Prepared statements or PDO, so your application is vulnerable to various types of attacks!

the problem is you were trying to convert a array for 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']."')"); 

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.