Search code examples
phpnotice

getting notice undefined index


I have read the following PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" however I haven't figured out the problem in my case.

I am getting the notice:undefined index below, when as far as I know I have defined infoID:

Notice: Undefined index: infoID in C:\xampp\htdocs\WebDevelopment\Bathrooms\functions.php on line 193

function info_byidx($sql) {
            include 'connect.php';
    $id = $_GET['infoID'];
    $select = $conn->prepare($sql);
    $select->bind_param('s', $id);
    $select->execute();
    $select->store_result();
    if ($select->num_rows > 0) {
        $meta = $select->result_metadata();
        while ($field = $meta->fetch_field()) {
            $params[] = &$row[$field->name];
        }
        call_user_func_array(array($select, 'bind_result'), $params);
        while ($select->fetch()) {
            if ($row['title'] == "NULL") {
                echo "<h3>".$row['subtitle']."</h3>\n<p>".$row['content']."</p>\n";
            }
            else if ($row['subtitle'] == "NULL") {
                echo "<h2>".$row['title']."</h2>\n<p>".$row['content']."</p>\n";
            }
            else {
            echo "<h2>".$row['title']."</h2>\n<h3>".$row['subtitle']."</h3>\n<p>".$row['content']."</p>\n";
            }

        }
        $select->close();
    }

}

infoID is defined thru:

http://localhost:1234/WebDevelopment/Bathrooms/info.php?pageID=2?infoID=x -- where is the value of generalID


Solution

  • http://localhost:1234/WebDevelopment/Bathrooms/info.php?pageID=2?infoID=x
    

    fix it to

    http://localhost:1234/WebDevelopment/Bathrooms/info.php?pageID=2&infoID=x
    

    just one ? at first, then use & to seperate next key=values.