-1

晚上所有,

我有一个重新编程问题,希望得到一些帮助

<div style="width:800px;height:100px;border:2px solid black;">
<html>
<body>
<br>
<?php

mysql_connect("localhost", "user", "password!") or die (mysql_error());
#echo "Connected to MYSQL ";
mysql_select_db("starforg_search") or die (mysql_error());
#echo "Connected to Data Base";
$query = "SELECT * FROM addserver";
$result = mysql_query ($query) or die (mysql_error());
while ($row = mysql_fetch_array($result)) {
        $value = $row['servername'];
        $value2 = $row['serveraddress'];
        $value3 = $row['portnumber'];
        $value4 = $row['description'];

}


?>

&nbsp;Server Name :<?php echo $_POST[$value1]; ?> 

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Server Address : <?php echo $_POST[$value2]; ?>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Port Number : <?php echo $_POST[$value3]; ?>
<br>
<br>
&nbsp;Server Description : <?php echo $_POST[$value4]; ?>
<br>
<br>

// Script by Akensai

<?php
$ip = $_POST[$value];
$port = $_POST[$value2];

if (!$socket = @fsockopen($ip, $port, $errno, $errstr, 30))
{
 echo "&nbsp;<font color='red'><CENTRE><strong>Server Is Offline!</strong></CENTRE></font>";
}
else 
{
 echo "&nbsp;<font color='green'><CENTRE><strong> Server Is Online!</strong></CENTRE></font>";  

  fclose($socket);
}
?>
<p>&nbsp;Server status is updated every hour</p>
<br>
</body>
</html> 
</div>

这是输出

在此处输入图像描述 不用说,我希望将 PHP 脚本中的值添加到 HTML 字段中

如果我只是回显并从 Mysql 调用 PHP 值,它工作正常,所以我必须有一些 HTML 语法错误,请尽可能纠正。

谢谢你的时间

4

4 回答 4

3

你只需要echo $value1;代替echo $_POST[$value1];

此外,没有$value1. 如果您想检索您的服务器名称,它应该只是$value

应该将相同的概念应用于您要检索的其他值。

$_POST 用于收集带有 method="post" 的表单中的值,而不是从 SQL 查询中检索值

于 2013-04-03T11:57:35.007 回答
1

您是否从 URL 获取值?如果没有,你为什么要使用 $_POST[...] ???

Server Name :<?php echo $_POST[$value1]; ?>

我想你需要像这样使用它:

Server Name :<?php echo $value1; ?>

这应该适合你。:)

于 2013-04-03T12:01:10.910 回答
1

POST 和 GET 是从表单或通过 URL 传递变量的方法。您在此代码中声明变量,因此只需使用$valuenot $_POST[$value]。您正在寻找一个 POSTed 变量,其名称包含在$value.

此外,您不应该在<div>标签之外有<html>标签。

这段代码应该可以工作。

<html>
<div style="width:800px;height:100px;border:2px solid black;">
<body>
<br>
<?php

mysql_connect("localhost", "starforg_forg13", "Tigger161!") or die (mysql_error());
#echo "Connected to MYSQL ";
mysql_select_db("starforg_search") or die (mysql_error());
#echo "Connected to Data Base";
$query = "SELECT * FROM addserver";
$result = mysql_query ($query) or die (mysql_error());
while ($row = mysql_fetch_array($result)) {
        $value1 = $row['servername'];
        $value2 = $row['serveraddress'];
        $value3 = $row['portnumber'];
        $value4 = $row['description'];

}

?>

&nbsp;Server Name :<?php echo $value1; ?> 

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Server Address : <?php echo $value2; ?>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Port Number : <?php echo $value3; ?>
<br>
<br>
&nbsp;Server Description : <?php echo $value4; ?>
<br>
<br>

// Script by Akensai

<?php
$ip = $value;
$port = $value2;

if (!$socket = @fsockopen($ip, $port, $errno, $errstr, 30))
{
 echo "&nbsp;<font color='red'><CENTRE><strong>Server Is Offline!</strong></CENTRE></font>";
}
else 
{
 echo "&nbsp;<font color='green'><CENTRE><strong> Server Is Online!</strong></CENTRE></font>";  

  fclose($socket);
}
?>
<p>&nbsp;Server status is updated every hour</p>
<br>
</body>
</div>
</html> 
于 2013-04-03T12:06:55.427 回答
1

我已经更正了代码,我希望这对你有用..

<html>
    <head>
    <title>
    Server-Info
    </title>
    </head>

    <body>
    <div style="width:800px;height:100px;border:2px solid black;">
    <br>
    <?php

    mysql_connect("localhost", "starforg_forg13", "Tigger161!") or die (mysql_error());
    #echo "Connected to MYSQL ";
    mysql_select_db("starforg_search") or die (mysql_error());
    #echo "Connected to Data Base";
    $query = "SELECT * FROM addserver";
    $result = mysql_query ($query) or die (mysql_error());
    while ($row = mysql_fetch_array($result)) {
            $value = $row['servername'];
            $value2 = $row['serveraddress'];
            $value3 = $row['portnumber'];
            $value4 = $row['description'];

    }


    ?>

    &nbsp;Server Name :<?php echo $value; ?> 

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Server Address : <?php echo $value2; ?>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Port Number : <?php echo $value3; ?>
    <br>
    <br>
    &nbsp;Server Description : <?php echo $value4; ?>
    <br>
    <br>

    // Script by Akensai

    <?php
    $ip = $value;
    $port = $value2;

    if (!$socket = @fsockopen($ip, $port, $errno, $errstr, 30))
    {
     echo "&nbsp;<font color='red'><CENTRE><strong>Server Is Offline!</strong></CENTRE></font>";
    }
    else 
    {
     echo "&nbsp;<font color='green'><CENTRE><strong> Server Is Online!</strong></CENTRE></font>";  

      fclose($socket);
    }
    ?>
    <p>&nbsp;Server status is updated every hour</p>
    <br>
</div>
</body>
</html> 
于 2013-04-03T12:14:08.027 回答