-2

I got error in my data viewing page, what is the correction for my php script

Here is my php script:

Notice: Undefined index: o in /home/tz005/public_html/COMP1687/view_data.php on line 64

<?php
        $con=mysqli_connect("mysql.cms.gre.ac.uk","tz005","punceg5L","mdb_tz005");

        if (is_numeric($_GET['o']))
        {
            $o=$_GET['o'];
        }else {
            $o=0;
            }

        if ($o >=1){
            $prev=$o-1;
            } else{
                $prev=0;
            }

1 Answers1

0

You need to add an isset() function to check if $_GET['o'] even exists.

Read more about isset() Here

use this:

 <?php
    $con=mysqli_connect("mysql.cms.gre.ac.uk","tz005","punceg5L","mdb_tz005");

    if (isset($_GET['o'] && is_numeric($_GET['o']))
    {
        $o=$_GET['o'];
    }else {
        $o=0;
        }

    if ($o >=1){
        $prev=$o-1;
        } else{
            $prev=0;
        }
iam-decoder
  • 2,554
  • 1
  • 13
  • 28