Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP从Mysql数据库中填充文本字段_Php_Mysql_Text_Populate - Fatal编程技术网

使用PHP从Mysql数据库中填充文本字段

使用PHP从Mysql数据库中填充文本字段,php,mysql,text,populate,Php,Mysql,Text,Populate,我试图用MySQL数据库中的数据填充文本字段,但我的代码似乎不起作用 任何帮助都将不胜感激 代码如下: <?php include ("../config.php"); // Connect to server and select database. mysql_select_db($db, $con); // get value of id that sent from address bar $id = $_GET['ID']; // Retrieve data from d

我试图用MySQL数据库中的数据填充文本字段,但我的代码似乎不起作用

任何帮助都将不胜感激

代码如下:

<?php include ("../config.php");

// Connect to server and select database.
mysql_select_db($db, $con);

// get value of id that sent from address bar
$id = $_GET['ID'];


// Retrieve data from database
$sql="SELECT * FROM members WHERE id='$id'";
$result=mysql_query($sql);

echo '<form name="Edit" method="post" action="update.php">

<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td align="center"><strong>Name:</strong></td>
<td align="center"><strong>Contact:</strong></td>
<td align="center"><strong>Division:</strong></td>
<td align="center"><strong>Rank:</strong></td>
</tr>';
            while ($row = mysql_fetch_assoc($result))
            {
            //we will echo these into the proper fields

        echo '<tr>';
        echo '<td align="center"><input name="Name" type="text" id="Name" value="'; echo $row['Name']; echo '"></td>';
        echo '<td align="center"><input name="Contact" type="text" id="Contact" value="'; echo $row["Contact"]; echo'" size="15"></td>';
        echo'<td>
        <select name="Divison">
        <option value="L4D2">L4D2</option>
        <option value="CSS">CSS</option>
        <option value="GMOD">GMOD</option>
        <option value="TF2">TF2</option>
        </select>
        </td>
        <td>
        <select name="Rank">
        <option value="Division Leader">Division Leader</option>
        <option value="Admin">Administrator</option>
        <option value="Member">Member</option>
        </select>
        </td>
        </tr>';


echo '<tr>';
        echo '<td align="center"><input type="submit" name="Submit" value="Submit"></td>
        </tr>
</table>
</td>
</form>';
}
echo '
</tr>
</table>
</body>
</html>';


// close connection
mysql_close();

?>

用完整修复程序编辑了我的答案:

<?php include ("../config.php");

// Connect to server and select database.
mysql_select_db($db, $con);

// get value of id that sent from address bar
$id = $_GET['ID'];

// Retrieve data from database
$sql="SELECT * FROM members WHERE id='$id'";
$result=mysql_query($sql);

echo '<form name="Edit" method="post" action="update.php">
            <table width="400" border="0" cellspacing="1" cellpadding="0">
                <tr>
                    <td align="center"><strong>Name:</strong></td>
                    <td align="center"><strong>Contact:</strong></td>
                    <td align="center"><strong>Division:</strong></td>
                    <td align="center"><strong>Rank:</strong></td>
                </tr>';
while ($row = mysql_fetch_assoc($result)) {
    //we will echo these into the proper fields

    echo '<tr>
                <td align="center"><input name="Name" type="text" id="Name" value="'.$row['Name'].'"></td>
                <td align="center"><input name="Contact" type="text" id="Contact" value="'.$row["Contact"].'" size="15"></td>
                <td>
                    <select name="Divison">
                        <option value="L4D2">L4D2</option>
                        <option value="CSS">CSS</option>
                        <option value="GMOD">GMOD</option>
                        <option value="TF2">TF2</option>
                    </select>
                </td>
                <td>
                    <select name="Rank">
                        <option value="Division Leader">Division Leader</option>
                        <option value="Admin">Administrator</option>
                        <option value="Member">Member</option>
                    </select>
                </td>
            </tr>';
}
echo     '<tr>
                <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
            </tr>
           </table>
        </form>';

// close connection
mysql_close();
?>


现在用这个替换整个编码并回答…?

只是一个猜测,但我认为您在db中的列名都是小写的。但是在php中有$row[“Contact”]。我想应该是$row[“contact”]

此代码:

$sql="SELECT * FROM members WHERE id='$id'";
应该是这样的

$sql="SELECT * FROM members WHERE id='{$id}'";
也使用

$result=mysql_query($sql) or die(mysql_error());
用于调试目的


删除mysql_close(),它应该可以工作

请确保使用具有合法ID的查询字符串,如example.com?ID=1。如果您正在发布表单,并且表单的post方法是post,则应使用$\u post['ID']而不是$\u GET['ID']。根据前面的评论,url中的ID为小写,将$\u GET['ID']更改为$\u GET['ID']

我可以这样做吗?使其他有问题的人不必阅读所有评论


新到这个网站,谢谢

谢谢,但是我仔细检查了箱子。谢谢。为语法添加了这些。谢谢。尝试将其更改为POST,但仍然无效。它也是一个合法的ID.value=“”。$row['Name']”这对我不起作用,我正在尝试在结果的一列中用值填充文本字段,这是我所做的名字: