简体   繁体   中英

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 ,

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM