David
David

Reputation: 23

Not getting anything from GET request

if (isset($_GET['id'])) {

        $movie_id=$_GET['id'];

        $sql="SELECT * FROM movies WHERE movie_id='$movie_id'";

        $run_sql=mysqli_query($connect,$sql);

        while ($row=mysqli_fetch_assoc($run_sql)) {

            $id=$row['movie_id'];
            $name=$row['Name'];
            $desc=$row['Description'];

            echo "<div id='breadcrumb'><a href='index.php'>Home</a> > <a href='movies.php'>Movies</a> $name</div>
    <div id='description'>
        <h1>$name</h1>
        <p>$desc</p>";
    }
}

this is the code and its shows nothing except the url ID which is passing through GET no other details are showing no errors either ,

Upvotes: 0

Views: 53

Answers (2)

RiggsFolly
RiggsFolly

Reputation: 94682

In these situations you should add some error checking to your code. In fact you should always be error checking

<?php

// some people develop on LIVE servers so make sure
// all error reporting is on while developing a script
ini_set('display_errors', 1); 
ini_set('log_errors',1); 
error_reporting(E_ALL); 
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

function single_page(){ 
    global $connect;

    if (isset($_GET['id'])) {

        $movie_id=$_GET['id'];

        $sql="SELECT * FROM movies WHERE movie_id='$movie_id'";

        $run_sql=mysqli_query($connect,$sql);

        if ( ! $run_sql ) {
            // output the error returned by the database
            echo 'SQL ERROR: ' . mysqli_error($connect);
            exit;
        }

        while ($row=mysqli_fetch_assoc($run_sql)) {

            $id=$row['movie_id'];
            $name=$row['Name'];
            $desc=$row['Description'];

            echo "<div id='breadcrumb'><a href='index.php'>Home</a> > <a href='movies.php'>Movies</a> $name</div>
                    <div id='description'>
                         <h1>$name</h1>
                         <p>$desc</p>
                    </div>";
        }
    }
}

This should at least tell you what the error is, if in fact it is generating an error in the compilation or execution of the query.

Upvotes: 0

Murad Hasan
Murad Hasan

Reputation: 9583

The main issue is with the URL.

Your URL is single.php?movie=3 and you're checking for $_GET['id']. So change your id by movie.

For the future, you have to code that is SQL Injection free and follow the Instruction given by @RiggsFolly.

Upvotes: 2

Related Questions