1

我将向您展示我的所有代码,以便您更好地掌握情况;

格式名.php

<table width="400" border="0" align="center" cellpadding="3" cellspacing="1">
<tr>
<td align="right"><strong>Add My Server</strong></td>
</tr>
<br>
</table>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form1" method="post" action="Inputtodbame.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="16%">Server Name</td>
<td width="2%">:</td>
<td width="82%"><input name="servername" type="text" id="subject" size="50"></td>
</tr>
<br>
<tr>
<td>Server Address </td>
<td>:</td>
<td><input name="serveraddress" type="text" id="name" size="50"></td>
</tr>
<br>
<tr>
<td>Port Number</td>
<td>:</td>
<td><input name="portnumber" type="text" id="customer_mail" size="50"></td>
</tr>
<br>
<tr>
<tr>
<td>Server Description</td>
<td>:</td>
<td><textarea name="description" cols="50" rows="4" id="detail"></textarea></td>
</tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Add My Server"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>

输入todbame.php

<?php

   header( 'Location: http://starforgeserversearch.com/serverindexame' ) ;

?>

<?php

define('DB_NAME', '');
define('DB_USER', '');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

if (!$link) {
    die('could not connect: ' . mysql_error());

}

$db_selected = mysql_select_db(DB_NAME, $link);

if  (!$db_selected) {
    die('Cant\'t use ' . DB_NAME . ': ' .mysql_error());


echo ('Connected');
}

$value = $_POST['servername'];
$value2 = $_POST['serveraddress'];
$value3 = $_POST['portnumber'];
$value4 = $_POST['description'];

$sql = "INSERT INTO addserverame (servername, serveraddress, portnumber, description) VALUES ('$value', '$value2', '$value3', '$value4')";

if  (!mysql_query($sql)) {
    die('Error: ' . mysql_error());
}


mysql_close();
?>

addserverindexame.php

<head>
<style type="text/css">
table { 
 color:black; background-color: white;
 border: 1px solid black;
  }
table td { 
 color:black; background-color: white; 
 border: 1px solid black;
  }  
</style>
</head>
<body>  

<table border="2" bordercolor="#000000" style="background-color:#FFFFFF" width="150%" cellpadding="1" cellspacing="0">  
<tr>
<div align='centre'>
    <td><font face="Arial, Helvetica, sans-serif"><b>Server Name</b></font</td>
    <td><font face="Arial, Helvetica, sans-serif"><b>Server Address</b></font</td>
    <td><font face="Arial, Helvetica, sans-serif"><b>Server Port</b></font</td>
    <td><font face="Arial, Helvetica, sans-serif"><b>Server Description</b></font</td>
    <td><font face="Arial, Helvetica, sans-serif"><b>Status</b></font></td>
    <td><font face="Arial, Helvetica, sans-serif"><b>Update</b></font></td>
</div>
</tr>
<?php

mysql_connect("localhost", "", "") 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 addserverame";
$result = mysql_query ($query) or die (mysql_error());

$num=mysql_numrows($result);

mysql_close();


$i=0;
while ($i < $num) {


        $value = mysql_result($result,$i,"servername");
        $value2 = mysql_result($result,$i,"serveraddress");
        $value3 = mysql_result($result,$i,"portnumber");
        $value4 = mysql_result($result,$i,"description");
        $id = mysql_result($result,$i,"ID");

ob_start();

if (!$socket = @fsockopen($value2, $value3, $errno, $errstr, 1))
{
  echo "&nbsp;<font color='red'><CENTRE><strong>OFFLINE</strong></CENTRE></font>";
}
else 
{
 echo "&nbsp;<font color='green'><CENTRE><strong>ONLINE</strong></CENTRE></font>";  

  fclose($socket);
}
$status = ob_get_contents();
ob_end_clean();
?>


<tr>
    <td><font face="Arial, Helvetica, sans-serif"><? echo $value; ?></font</td>
    <td><font face="Arial, Helvetica, sans-serif"><? echo $value2; ?></font</td>
    <td><font face="Arial, Helvetica, sans-serif"><? echo $value3; ?></font</td>
    <td><font face="Arial, Helvetica, sans-serif"><? echo $value4; ?></font</td>
    <td><font face="Arial, Helvetica, sans-serif"><? echo $status; ?></font</td>
    <td align="center"><a href="updateame.php?id=<? echo $id; ?>">update</a></td>
</tr>


<?
$i++;

}

?>  
</table>

注意:上面的每件事都很好,我可以为 MySQL 字段增加价值快乐的日子!!。

更新名称.php

<?php

mysql_connect("localhost", "", "x") or die (mysql_error());
#echo "Connected to MYSQL ";
mysql_select_db("starforg_search") or die (mysql_error());
#echo "Connected to Data Base";

$id=$_GET['ID'];

$query = "SELECT * FROM addserverame WHERE ID='$id'";
$result = mysql_query ($query) or die (mysql_error());


        $value = mysql_result($result,$i,"servername");
        $value2 = mysql_result($result,$i,"serveraddress");
        $value3 = mysql_result($result,$i,"portnumber");
        $value4 = mysql_result($result,$i,"description");
        $id = mysql_result($result,$i,"ID");



?>


        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Add Your Server</title>
<link rel="stylesheet" type="text/css" href="view.css" media="all">
<script type="text/javascript" src="view.js"></script>

</head>
<body id="main_body" >

    <img id="top" src="top.png" alt="">
    <div id="form_container">

        <h1><a>Add Your Server</a></h1>
        <form id="form_606591" class="appnitro"  method="post" action="updateameac.php">
                    <div class="form_description">
            <h2>Add Your Server</h2>
            <p></p>
        </div>                      
            <ul >

                    <li id="li_1" >
        <label class="description" for="servername">Server Name </label>
        <div>
            <input id="element_1" name="servername" class="element text medium" type="text" maxlength="255" value=""/> 
        </div><p class="guidelines" id="guide_1"><small>Enter your server name here NOT your server address.</small></p> 
        </li>       <li id="li_2" >
        <label class="description" for="serveraddress">Server Address </label>
        <div>
            <input id="element_2" name="serveraddress" class="element text medium" type="text" maxlength="255" value=""/> 
        </div><p class="guidelines" id="guide_2"><small>This will the DNS name of your server</small></p> 
        </li>       <li id="li_3" >
        <label class="description" for="portnumber">PortNumber </label>
        <div>
            <input id="element_3" name="portnumber" class="element text medium" type="text" maxlength="255" value=""/> 
        </div><p class="guidelines" id="guide_3"><small>This will be the port your server is using.</small></p> 
        </li>       <li id="li_4" >
        <label class="description" for="description">Server Description </label>
        <div>
            <textarea id="element_4" name="description" class="element textarea medium"></textarea> 
        </div><p class="guidelines" id="guide_4"><small>Enter server description/rules here.</small></p> 
        </li>
        div>
            <input id="ID" name="ID" class="element text medium" type="hidden" maxlength="255" value=""/> 
        </div><p class="guidelines" id="guide_5"><small>This will be the port your server is using.</small></p> 
        </li>       <li id="li_6" >

                    <li class="buttons">
                <input type="hidden" name="form_id" value="606591" />

                <input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
        </li>
            </ul>
        </form> 
        <div id="footer">
            Generated by <a href="http://www.phpform.org">pForm</a>
        </div>
    </div>

    </body>
</html>

<?php
mysql_close();

?>

更新ameac.php

<?php
mysql_connect("localhost", "xxxx", "xxxx") or die (mysql_error());
echo "Connected to MYSQL ";
mysql_select_db("starforg_search") or die (mysql_error());
echo "Connected to Data Base";


$sql="UPDATE addserverame SET servername='$value', serveraddress='$value2', portnumber='$value3', description='$value4' WHERE ID='$id'";
$result=mysql_query($sql);

if($result){
echo "Successful";
echo "<BR>";
}

else {
echo "ERROR";
}

?>

问题 如果我进入我想要编辑的字段并单击更新 href 我被带到一个页面以输入新值我这样做,updateameac.php 显示成功但是我查看这些字段并且它们没有被编辑。

我想要的是

我希望编辑能够反映在数据库中,基本上它可以正常工作,哈哈。我是 PHP 的初学者,所以我希望你们中的一位优秀的程序员能够解决我的问题。

我怀疑我在 updateameac.php 中没有正确显示字段值,我不知道如何纠正它。

4

1 回答 1

2

updateameac.php你也必须写这一行

$value = $_POST['servername'];
$value2 = $_POST['serveraddress'];
$value3 = $_POST['portnumber'];
$value4 = $_POST['description'];
$id = $_POST['ID'];
于 2013-04-07T04:05:46.637 回答