Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.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 试图在html文本字段中显示mysql数据_Php_Html_Mysql - Fatal编程技术网

Php 试图在html文本字段中显示mysql数据

Php 试图在html文本字段中显示mysql数据,php,html,mysql,Php,Html,Mysql,我希望能够从我的web浏览器查看和编辑表中包含的信息,但是我无法获取当前值,无法将其拉到html文本字段中 有人能解释一下我对php很陌生吗 表名称:请求详细信息 列名:id、名称、电子邮件地址 我的PHP代码是: <? $order = "SELECT * FROM request_details WHERE id='$id'"; $result = mysql_query($order); $row = mysql_fetch_array($result); ?> 这样做吗

我希望能够从我的web浏览器查看和编辑表中包含的信息,但是我无法获取当前值,无法将其拉到html文本字段中

有人能解释一下我对php很陌生吗

表名称:请求详细信息

列名:id、名称、电子邮件地址

我的PHP代码是:

<?
$order = "SELECT * FROM request_details WHERE id='$id'";
$result = mysql_query($order);
$row = mysql_fetch_array($result);
?>
这样做吗

   <input type="hidden" name="id" value="<?php echo $row['id'] ;?>" />

  <input type="text" name="name" size="20" value="<?php echo $row['name']; ?>" />

  <input type="text" name="email_address" size="40" value="<?php echo $row['email_address']; ?>" />

您可以这样做:

<input type="text" name="email_address" size="40" value="<?=$row['email_address']?>">

将php代码更改为

$row=mysql\u fetch\u数组($result,mysql\u ASSOC)

还要更改HTML代码,如下所示

    <input type="hidden" name="id" value="<?php echo $row['id'] ;?>" />

您的代码不完整,它丢失了行调用中的定义。它不知道$row[name],因为变量应该由引号定义

<input type="text" name="name" size="20" value="<? echo $row['name']; ?>">
<input type="text" name="email_address" size="40" value="<? echo $row['email_address']; ?>">

如果您的URL是edit\u form.php?id=19

您需要像这样编写查询:

$order = "SELECT * FROM request_details WHERE id='$_GET[id]'";

我对孔代码进行了更正,它起作用了

<html>
<head>
<title>PAGE Edit</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table>
  <tr>
    <td align="center">EDIT DATA</td>
  </tr>
  <tr>
    <td>
      <table border="1">
      <?php
      include"db.inc.php";//database connection
      $order = "SELECT * FROM data_employees";
      $result = mysql_query($order);
      while ($row=mysql_fetch_array($result)){
      // Print "<th>Name:</th> <td>".$data['user'] . "</td> "; 
        echo ("<tr><td>".$row['name']."</td>");
        echo ("<td>".$row['employees_number']."</td>");
        echo ("<td>".$row['address']."</td>");
        echo ("<td><a href=edit_form.php?id=".$row['employees_number'].">Edit</a></td></tr>"); 
      }
      ?>
      </table>
    </td>
   </tr>
</table>
</body>
</html>

页面编辑
编辑数据
第二部分:调用edit_form.php进行编辑

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Form Edit Data</title>
</head>

<body>
<table border=1>
  <tr>
    <td align=center>Form Edit Employees Data</td>
  </tr>
  <tr>
    <td>
      <table>
      <?php
      $id=$_GET['id']; 

      include "db.inc.php";//database connection
      $order = "SELECT * FROM data_employees 
where employees_number='$id'";
      $result = mysql_query($order);
      $row = mysql_fetch_array($result);
      ?>
      <form method="post" action="edit_data.php">
      <input type="hidden" name="id" value="<?php echo "$row[employees_number]"?>">
        <tr>        
          <td>Name</td>
          <td>
            <input type="text" name="name" 
        size="20" value="<?php echo "$row[name]"?>">
          </td>
        </tr>
        <tr>
          <td>Address</td>
          <td>
            <input type="text" name="address" size="40" 
          value="<?php echo "$row[address]"?>">
          </td>
        </tr>
        <tr>
          <td align="right">
            <input type="submit" 
          name="submit value" value="Edit">
          </td>
        </tr>
      </form>
      </table>
    </td>
  </tr>
</table>
</body>
</html>

表单编辑数据
表单编辑员工数据

你打开错误报告了吗?你有错误吗?您采取了哪些故障排除步骤来确定问题?我想您忘记了行索引名称周围的引号$row[“name”]而不是$row[name]您的代码在使用它时极易受到攻击。您确实应该调查PDO()和准备好的语句。这就像在你把贵重物品留在车里去上班的时候把车窗打开一样。要调试,请尝试:
var\u dump($row)您得到了什么结果?@user2717967那么问题不在这里,这是您如何从数据库回显值。我猜您的问题在于查询中的
$id
。你有没有试着回显它,看看它是否有价值?我试着只是回显并显示在标签中,但也没有任何乐趣,所以我想这是一件非常简单的事情,我说的只是尝试
echo$id
在您的查询之前,查看是否有回声。然后您没有$id,看看您将$di带到何处,您的问题在于此id。这就是为什么您的查询就像您说的
其中id=nothing
从上一页代码是echo(“”);id,定义为数据库中的列名
  $id = $_GET['id'] ;
<input type="text" name="email_address" size="40" value="<?=$row['email_address']?>">
    <input type="hidden" name="id" value="<?php echo $row['id'] ;?>" />
<input type="text" name="name" size="20" value="<? echo $row['name']; ?>">
<input type="text" name="email_address" size="40" value="<? echo $row['email_address']; ?>">
$order = "SELECT * FROM request_details WHERE id='$_GET[id]'";
<html>
<head>
<title>PAGE Edit</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table>
  <tr>
    <td align="center">EDIT DATA</td>
  </tr>
  <tr>
    <td>
      <table border="1">
      <?php
      include"db.inc.php";//database connection
      $order = "SELECT * FROM data_employees";
      $result = mysql_query($order);
      while ($row=mysql_fetch_array($result)){
      // Print "<th>Name:</th> <td>".$data['user'] . "</td> "; 
        echo ("<tr><td>".$row['name']."</td>");
        echo ("<td>".$row['employees_number']."</td>");
        echo ("<td>".$row['address']."</td>");
        echo ("<td><a href=edit_form.php?id=".$row['employees_number'].">Edit</a></td></tr>"); 
      }
      ?>
      </table>
    </td>
   </tr>
</table>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Form Edit Data</title>
</head>

<body>
<table border=1>
  <tr>
    <td align=center>Form Edit Employees Data</td>
  </tr>
  <tr>
    <td>
      <table>
      <?php
      $id=$_GET['id']; 

      include "db.inc.php";//database connection
      $order = "SELECT * FROM data_employees 
where employees_number='$id'";
      $result = mysql_query($order);
      $row = mysql_fetch_array($result);
      ?>
      <form method="post" action="edit_data.php">
      <input type="hidden" name="id" value="<?php echo "$row[employees_number]"?>">
        <tr>        
          <td>Name</td>
          <td>
            <input type="text" name="name" 
        size="20" value="<?php echo "$row[name]"?>">
          </td>
        </tr>
        <tr>
          <td>Address</td>
          <td>
            <input type="text" name="address" size="40" 
          value="<?php echo "$row[address]"?>">
          </td>
        </tr>
        <tr>
          <td align="right">
            <input type="submit" 
          name="submit value" value="Edit">
          </td>
        </tr>
      </form>
      </table>
    </td>
  </tr>
</table>
</body>
</html>
<?php
//edit_data.php
$name=$_POST['name'];
$address=$_POST['address'];
$id=$_POST['id'];
include "db.inc.php";
$order = "UPDATE data_employees 
          SET name='$name', 
              address='$address' 
          WHERE 
          employees_number='$id'";
mysql_query($order);
header("location:edit.php");
?>