简体   繁体   中英

Weird Title from another Page

For some reason I am getting "MySQL Config Page" as my title, even though I have this nowhere on my page. Why is this?

<?php
include "mysql_config.php";
$con = mysql_connect($host, $user, $pass);
$org_id = mysql_real_escape_string(html2txt($_GET['org_id']));
$resorgname = mysql_query("SELECT org_name from organization WHERE org_id='".$org_id."'");
if (!$resorgname) {
    die('Invalid query, please contact administrator');
}
while ($orgnamerow = mysql_fetch_array($resorgname)) {
    $org_name = $orgnamerow['org_name'];
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head><title><?php ECHO $org_name; ?></title></head>
    <body>
        ...

Here is the generated page source for one of the pages:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head><title>MySQL Config Page</title></head>
    <body>
    </body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head><title>Letsgo</title></head>
    <body>
...

Looks like an issue in you mysql_config.php that you included. The browser will take the first head part that it encounters. My suspicion is the included page is causing this.

Just looked at the output HTML and your mysql_config is printing the HTML. It should purely do config. Try require_once("mysql_config.php"); and remove any HTML from the config php.

It's getting the title for the page from the MySQL query you are performing. $org_name comes from the array $orgnamerow (set by the while loop, which goes through the MySQL rows from your query), which is most likely the first MySQL row on the organization table.

So the title is coming from org_name in your organization table.

It looks like mysql_config.php is a page you use for displaying in its own right, which I suspect is why you have HTML in there (maybe you are using it to display the settings, or something).

Therefore, while it may have your MySQL settings in it, you can't really use it in the way you have. A solution is strip all HTML out of mysql_config.php and jsut have configuration in it. If you're using the current mysql_config.php file for other things, then create a new file - eg mysql_display.php - and include mysql_config.php into that.

If you're not using mysql_config.php for anything other than config, then there's no reason to have any HTML in it at all.

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