-1

Evening all,

I have a reprogramming issue and would love some assistance

<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>

This is the output

enter image description here needless to say i want the values from the PHP script to be added to the HTML fields

It works fine if i just echo and call the PHP values from Mysql so i must have some HTML syntax errors please correct if possible.

Thanks for your time

Ben

6
  • 3
    Summary: 'I have some code and you need to fix it.' Please read "How to Ask" to make good questions. Some tips on your code: 1) don't use <br> and $nbsp; those are bad practises, use CSS margin/padding; 2) or die is not an error handling; 3) put the PHP logic at the top of your page; 4) don't put div elements before <html>; 5) you're missing a doctype.
    – Wouter J
    Apr 3, 2013 at 11:58
  • 1
    6) mysql_* functions are deprecated, use PDO or mysqli_*. 7) it's better to use separate css file than putting styles in style attribute. 8) tags should be lower-cased.
    – Leri
    Apr 3, 2013 at 12:01
  • is this DB ($query = "SELECT * FROM addserver";) query executed in same page or another page..
    – MKV
    Apr 3, 2013 at 12:01
  • 1
    if u are executed that query in a same page means why using this $_POST[$value] directly echo the value of $value change this to Server Name :<?php echo $_POST[$value1]; ?> to Server Name :<?php echo $value1; ?> and re arrange in your code Server Address : <?php echo $value2; ?> Port Number : <?php echo $value3; ?> Server Description : <?php echo $value4; ?>
    – MKV
    Apr 3, 2013 at 12:09
  • @WouterJ i don't see how that was a bad question but ok... Apr 3, 2013 at 12:17

4 Answers 4

3

You just need to echo $value1; instead of echo $_POST[$value1];

Also, There is no $value1. If you want to retrieve your Server Name it should only be $value

The same concept should be applied for other values that you want to retrieve.

$_POST is used to collect values in a form with method="post" not to retrieve value from your SQL query

1
  • 1
    man all the votes down :/ haters gunna hate, Buutttt thank you for your response and time :) Apr 3, 2013 at 12:23
1

POST and GET are methods for passing variables from forms or through the URL. You declare your variables in this code, so just use $value not $_POST[$value]. You were looking for a POSTed variable with the name contained in $value.

Additionally, you shouldn't have <div> tags outside of the <html> tags.

This code should work.

<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> 
1

I have corrected the code and I hope this will work for you..

<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> 
1

Are you getting values from URL ? If not, why are you using $_POST[...] ???

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

I guess you need to use it as just:

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

This should work for you. :)

Not the answer you're looking for? Browse other questions tagged or ask your own question.