Notice: Undefined index: pg in C: xampp htdocs pirataflixS Assets Movies.php on line 36

Asked

Viewed 27 times

0

You’re making this mistake for me, I can’t solve it, can you give me a boost? I’m trying to register youtube links on DB, it’s going normal, and showing the videos too, but it’s this line of error on the page.

<?php
// Inclui arquivo de conexão com banco de dados
include_once 'dataBase.php';
$pg = $_GET['pg'];
if(isset($pg)){
    $pg = $pg;
}else{
    $pg = 1;
}
$quantidade = 10;
$inicio = ($pg*$quantidade) - $quantidade;
                
$result = $mysqli->query("SELECT * FROM movies ORDER BY id ASC LIMIT $inicio, $quantidade");
while ($linha = $result->fetch_array()){
    $id = $linha['id'];
    $title = $linha['title'];
    $linkMovie = $linha['linkMovie'];
                    
    echo "<center> <h2>$title</h2><br>
    <iframe width='100' height='200' src='https://www.youtube.com/embed/$linkMovie' frameborder='0' allow='accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture' allowfullscreen></iframe><br></center>";
    }
                    
    $result = $mysqli->query("SELECT * FROM movies");
    $total_registros = $result->num_rows;
    $paginas = ceil($total_registros/$quantidade);
    $links = 1;
                
                
?>
  • This error happens pq you are not passing the parameter to your GET['pg'].

1 answer

1


Good afternoon dear, I believe the following code solves the problem:

$pg = 1; //default
if(isset($_GET['pg'])){
 $pg = $pg;
}
  • Thank you very much, corrected, thanks,

Browser other questions tagged

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