How do I return a message if $_GET is null or does not match any database entries?

Posted by CT on Stack Overflow See other posts from Stack Overflow or by CT
Published on 2010-05-23T23:09:55Z Indexed on 2010/05/23 23:40 UTC
Read the original article Hit count: 287

Filed under:
|
|
|

I am working on designing an IT Asset database. Here I am working on a page used to view details on a specific asset determined by an asset id.

Here I grab $id from $_GET["id"];

When $id is null, the page does not load. When $id does not match any entry within the database, the page loads but no asset table is printed.

In both these cases, I would like to display a message like "There is no database entry for that Asset ID"

How would this be handled? Thank you.

<?php

/* 
*  View Asset
*
*/

# include functions script
include "functions.php";

$id = $_GET["id"];
ConnectDB();
$type = GetAssetType($id);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title>Wagman IT Asset</title>
</head>

<body>
    <div id="page">
                <div id="header">
                  <img src="images/logo.png" />
                </div>

                </div>

                <div id="content">
                    <div id="container">

                        <div id="main">
                        <div id="menu">
                            <ul>
                                <table width="100%" border="0">
                                <tr>
                                <td width="15%"></td>
                                <td width="30%%"><li><a href="index.php">Search Assets</a></li></td>
                                <td width="30%"><li><a href="addAsset.php">Add Asset</a></li></td>
                                <td width="25%"></td>
                                </tr>
                                </table>
                          </ul>
                        </div>
                        <div id="text">
                        <ul>
                        <li>
                        <h1>View Asset</h1>
                        </li>
                        </ul>
                        <br />
                        <?php
                        switch ($type){
                        case "Server":
                        $result = QueryServer($id);
                        $ServerArray = GetServerData($result);
                        PrintServerTable($ServerArray);
                        break;
                        case "Desktop";

                        break;
                        case "Laptop";

                        break;
                        }
                        ?>


                        </div>

                        </div>
                </div>
                <div class="clear"></div>
                <div id="footer" align="center">
                    <p>&nbsp;</p>
                </div>
                </div>
                <div id="tagline">
                Wagman Construction - Bridging Generations since 1902
                </div>


</body>
</html>

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql