Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 802573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:37:32+00:00 2026-05-14T23:37:32+00:00

This page uses $_GET to grab an asset id and query a mysql database

  • 0

This page uses $_GET to grab an asset id and query a mysql database and return some information.

If ‘id’ does not match anything, no results are displayed but the page looks fine. If ‘id’ is null an error would occur at $id = $_GET["id"] or die(mysql_error()); When this occurs, they page layout is not displayed correctly. How do I fix this?

Bonus question: How would I get a message like “No matching results found” or something when the id does not match any id in the database or is null.

Thank you.

<!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>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><li><a href="index.php">Search Assets</a></li></td>
                                <td><li><a href="browse.php">Browse Assets</a></li></td>
                                <td><li><a href="add_asset.php">Add Asset</a></li></td>
                                <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                </tr>
                                </table>
                          </ul>
                        </div>
                        <div id="text">
                        <ul>
                        <li>
                        <h1>View Asset</h1>
                        </li>
                        </ul>
<table width="100%" border="0" cellpadding="2">
<?php

//make database connect
mysql_connect("localhost", "asset_db", "asset_db") or die(mysql_error());
mysql_select_db("asset_db") or die(mysql_error());

//get asset
$id = $_GET["id"] or die(mysql_error());
//get type of asset
$sql = "SELECT asset.type
From asset
WHERE asset.id = $id";
$result = mysql_query($sql)
or die(mysql_error());
$row = mysql_fetch_assoc($result);
$type = $row['type'];

switch ($type){
case "Server":
$sql = "
SELECT asset.id
,asset.company
,asset.location
,asset.purchase_date
,asset.purchase_order
,asset.value
,asset.type
,asset.notes
,server.manufacturer
,server.model
,server.serial_number
,server.esc
,server.user
,server.prev_user
,server.warranty
FROM asset
LEFT JOIN server
    ON server.id = asset.id
WHERE asset.id = $id
";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result))
{
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Asset ID:</td><td>";
    $id = $row['id'];
    setcookie('id', $id);
    echo "$id</td></tr>";
    echo "<tr<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Company:</td><td>";
    $company = $row['company'];
    setcookie('company', $company);
    echo "$company</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Location:</td><td>";
    $location = $row['location'];
    setcookie('location', $location);
    echo "$location</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Purchase Date:</td><td>";
    $purchase_date = $row['purchase_date'];
    setcookie('purchase_date', $purchase_date);
    echo "$purchase_date</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Purchase Order:</td><td>";
    $purchase_order = $row['purchase_order'];
    setcookie('purchase_order', $purchase_order);
    echo "$purchase_order</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Value:</td><td>";
    $value = $row['value'];
    setcookie('value', $value);
    echo "$value</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Type:</td><td>";
    $type = $row['type'];
    setcookie('type', $type);
    echo "$type</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Notes:</td><td>";
    $notes = $row['notes'];
    setcookie('notes', $notes);
    echo "$notes</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Manufacturer:</td><td>";
    $manufacturer = $row['manufacturer'];
    setcookie('manufacturer', $manufacturer);
    echo "$manufacturer</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Model / Description:</td><td>";
    $model = $row['model'];
    setcookie('model', $model);
    echo "$model</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Serial Number / Service Tag:</td><td>";
    $serial_number = $row['serial_number'];
    setcookie('serial_number', $serial_number);
    echo "$serial_number</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Express Service Code:</td><td>";
    $esc = $row['esc'];
    setcookie('esc', $esc);
    echo "$esc</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>User:</td><td>";
    $user = $row['user'];
    setcookie('user', $user);
    echo "$user</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Previous User:</td><td>";
    $prev_user = $row['prev_user'];
    setcookie('prev_user', $prev_user);
    echo "$prev_user</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Warranty:</td><td>";
    $warranty = $row['warranty'];
    setcookie('warranty', $warranty);
    echo "$warranty</td></tr>";
}

break;


case "Laptop":
$sql = "
SELECT asset.id
,asset.company
,asset.location
,asset.purchase_date
,asset.purchase_order
,asset.value
,asset.type
,asset.notes
,laptop.manufacturer
,laptop.model
,laptop.serial_number
,laptop.esc
,laptop.user
,laptop.prev_user
,laptop.warranty
FROM asset
LEFT JOIN laptop
    ON laptop.id = asset.id
WHERE asset.id = $id
";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result))
{
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Asset ID:</td><td>";
    $id = $row['id'];
    setcookie('id', $id);
    echo "$id</td></tr>";
    echo "<tr<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Company:</td><td>";
    $company = $row['company'];
    setcookie('company', $company);
    echo "$company</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Location:</td><td>";
    $location = $row['location'];
    setcookie('location', $location);
    echo "$location</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Purchase Date:</td><td>";
    $purchase_date = $row['purchase_date'];
    setcookie('purchase_date', $purchase_date);
    echo "$purchase_date</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Purchase Order:</td><td>";
    $purchase_order = $row['purchase_order'];
    setcookie('purchase_order', $purchase_order);
    echo "$purchase_order</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Value:</td><td>";
    $value = $row['value'];
    setcookie('value', $value);
    echo "$value</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Type:</td><td>";
    $type = $row['type'];
    setcookie('type', $type);
    echo "$type</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Notes:</td><td>";
    $notes = $row['notes'];
    setcookie('notes', $notes);
    echo "$notes</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Manufacturer:</td><td>";
    $manufacturer = $row['manufacturer'];
    setcookie('manufacturer', $manufacturer);
    echo "$manufacturer</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Model / Description:</td><td>";
    $model = $row['model'];
    setcookie('model', $model);
    echo "$model</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Serial Number / Service Tag:</td><td>";
    $serial_number = $row['serial_number'];
    setcookie('serial_number', $serial_number);
    echo "$serial_number</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Express Service Code:</td><td>";
    $esc = $row['esc'];
    setcookie('esc', $esc);
    echo "$esc</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>User:</td><td>";
    $user = $row['user'];
    setcookie('user', $user);
    echo "$user</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Previous User:</td><td>";
    $prev_user = $row['prev_user'];
    setcookie('prev_user', $prev_user);
    echo "$prev_user</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Warranty:</td><td>";
    $warranty = $row['warranty'];
    setcookie('warranty', $warranty);
    echo "$warranty</td></tr>";
}

        break;  
case "Desktop":
$sql = "
SELECT asset.id
,asset.company
,asset.location
,asset.purchase_date
,asset.purchase_order
,asset.value
,asset.type
,asset.notes
,desktop.manufacturer
,desktop.model
,desktop.serial_number
,desktop.esc
,desktop.user
,desktop.prev_user
,desktop.warranty
FROM asset
LEFT JOIN desktop
    ON desktop.id = asset.id
WHERE asset.id = $id
";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result))
{
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Asset ID:</td><td>";
    $id = $row['id'];
    setcookie('id', $id);
    echo "$id</td></tr>";
    echo "<tr<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Company:</td><td>";
    $company = $row['company'];
    setcookie('company', $company);
    echo "$company</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Location:</td><td>";
    $location = $row['location'];
    setcookie('location', $location);
    echo "$location</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Purchase Date:</td><td>";
    $purchase_date = $row['purchase_date'];
    setcookie('purchase_date', $purchase_date);
    echo "$purchase_date</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Purchase Order:</td><td>";
    $purchase_order = $row['purchase_order'];
    setcookie('purchase_order', $purchase_order);
    echo "$purchase_order</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Value:</td><td>";
    $value = $row['value'];
    setcookie('value', $value);
    echo "$value</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Type:</td><td>";
    $type = $row['type'];
    setcookie('type', $type);
    echo "$type</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Notes:</td><td>";
    $notes = $row['notes'];
    setcookie('notes', $notes);
    echo "$notes</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Manufacturer:</td><td>";
    $manufacturer = $row['manufacturer'];
    setcookie('manufacturer', $manufacturer);
    echo "$manufacturer</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Model / Description:</td><td>";
    $model = $row['model'];
    setcookie('model', $model);
    echo "$model</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Serial Number / Service Tag:</td><td>";
    $serial_number = $row['serial_number'];
    setcookie('serial_number', $serial_number);
    echo "$serial_number</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Express Service Code:</td><td>";
    $esc = $row['esc'];
    setcookie('esc', $esc);
    echo "$esc</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>User:</td><td>";
    $user = $row['user'];
    setcookie('user', $user);
    echo "$user</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Previous User:</td><td>";
    $prev_user = $row['prev_user'];
    setcookie('prev_user', $prev_user);
    echo "$prev_user</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Warranty:</td><td>";
    $warranty = $row['warranty'];
    setcookie('warranty', $warranty);
    echo "$warranty</td></tr>";
}
        break;  
}

?>
</table>
<br />
<br />
<table width="100%" border="0">
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><a href="#">Add Software</a></td>
<td><a href="#">Edit Asset</a></td>
<td><a href="#">Delete Asset</a></td>
</tr>
</table>
                        </div>

                        </div>
                </div>
                <div class="clear"></div>
                <div id="footer" align="center">
                    <p>&nbsp;</p>
                </div>
                </div>
                <div id="tagline">

                </div>


</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:37:33+00:00Added an answer on May 14, 2026 at 11:37 pm

    Your layout breaks because you “die” right in the middle of outputting HTML. Your page will output the content up to the table just after “View Asset”, then if the script dies, it will stop right there and not output a single character below. You’ll end up with a table start tag being output but not closed, nor will any of the divs, the body or html tags be closed.

    You’ll also find that you cannot use the setcookie function once any HTML has started to be output.

    I’d suggest completely separating your PHP logic and HTML output – preferably into separate files, or alternatively PHP code at the top of the file and HTML below. Do your logic and save your variables in PHP first, then output all your PHP normally, just including the appropriate variables where necessary. Something like this:

    <?php
    // connect to the database and run your query here
    // save results into an array, something like this:
    $rows = array();
    while($row = mysql_fetch_assoc($result))
    {
        // processing with $row here if needed
        $rows[] = $row;
    }
    
    //rest of PHP code
    
    ?>
    <!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">
    <!-- rest of the opening HTML code here -->
    
    <table width="100%" border="0" cellpadding="2">
    <?php foreach ( $rows as $row ) : ?>
    <tr>
        <td>Addet ID:</td>
        <td><?php echo $row['id'] ?></td>
    </tr>
    <tr>
    ...etc
    </tr>
    <?php endforeach; ?>
    </table>
    
    <!-- rest of the closing HTML code here -->
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.