我正在尝试使用PHP创建一个编辑表单

时间:2014-02-18 23:40:34

标签: php html mysql load edit

我的html代码,但保存为Modyfyitems.php

<?include 'Login/login_check.php';?>
<?include 'inc/Application.php';?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<style type="text/css">
body {
   background-color: #284489;
   text-shadow: 0px 0px #FFFFFF;
   color: #FFFFFF;
}
form1 {
   background-color: #FFFFFF
}
</style>
<link rel="stylesheet" type="text/css" media="all" href="css/jsDatePick_ltr.min.css" />

 <script type="text/javascript" src="js/jsDatePick.min.1.3.js"></script>

 <script type="text/javascript">
   window.onload = function(){
      new JsDatePick({
         useMode:2,
         target:"datereceived",
         dateFormat:"%d-%M-%Y"
      });
   };
</script>

</head>

<body>
<h2>&nbsp;</h2>
<form id="form1" name="form1" aling="center" method="post">
  <div align="center">
    <table width="393" border="0">
      <tr>
        <td><div align="center">
          <h2><span style="text-align: left; color: #FFFFFF;">LAC Product Registery</span></h2>
        </div></td>
      </tr>
    </table>
    <p>
      <input type="button" name="button4" id="button4" onClick="location.href='Menu.php'" value="Menu">
    </p>
  </div>
  <div align="center" style="background-color: #FFFFFF; color: #000000;">
    <table width="827" border="0" align="center">
      <tr bgcolor="#FDFDFD">
        <td width="501"><h3>Modify Items</h3>
          <p>Enter Code
            <input name="barcode" type="text" autofocus required="required" id="barcode" form="form1">
            <input type="submit" name="search" id="search" onClick="location.href='Actions/loaditem.php'" value="Search">
          </p>
          <table width="500" border="0" cellpadding="10" cellspacing="1">
          <tr>
            <td width="141" bgcolor="#E8F1FC">Sponsor</td>
            <td width="316" bgcolor="#E8F1FC"><?include 'Actions/loadLists/sponsor.php';?></td>
          </tr>
          <tr>
            <td bgcolor="#f1f4f9">Date Received</td>
            <td bgcolor="#f1f4f9"><input type="datetime" name="datereceived" value="<? echo $DateReceived; ?>" id="datereceived" placeholder="17-FEB-2014"></td>
          </tr>
          <tr>
            <td bgcolor="#E8F1FC"><strong>Code</strong></td>
            <td bgcolor="#E8F1FC">&nbsp;</td>
          </tr>
          <tr>
            <td bgcolor="#F1F4F9"><ul>
              <li> Container</li>
            </ul></td>
            <td bgcolor="#F1F4F9"><input name="container" type="number" value="<? echo $Container; ?>" id="container" placeholder="0152"></td>
          </tr>
          <tr>
            <td bgcolor="#E8F1FC"><ul>
              <li>Pallet</li>
            </ul></td>
            <td bgcolor="#E8F1FC"><input name="pallet" type="number" value="<? echo $Pallet; ?>" id="number5" placeholder="0028"></td>
          </tr>
          <tr>
            <td bgcolor="#F1F4F9"><ul>
              <li>Amount</li>
            </ul></td>
            <td bgcolor="#F1F4F9"><input name="amount" type="number" id="number6" value="<? echo $Amount; ?>" placeholder="0002"></td>
          </tr>
          <tr>
            <td bgcolor="#E8F1FC">Description</td>
            <td bgcolor="#E8F1FC"><?include 'Actions/loadLists/descriptions.php';?></td>
          </tr>
          <tr>
            <td bgcolor="#F1F4F9">Remarks</td>
            <td bgcolor="#F1F4F9"><textarea name="remarks" id="remarks"><? echo $Remarks; ?></textarea></td>
          </tr>
          <tr>
            <td bgcolor="#E8F1FC">Location</td>
            <td bgcolor="#E8F1FC"><?include 'Actions/loadLists/locations.php';?></td>
          </tr>
          <tr>
            <td height="18">&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
        <td width="316" valign="top" style="text-align: left"><p><br>
        </p>
          <p>          Documents</p>
        <p>&nbsp; </p></td>
      </tr>
    </table>
  </div>
  <table width="383" border="0" align="center">
    <tr>
      <td width="377" style="text-align: center"><input type="button" name="button" id="button" value="Save">
        ...
          <input type="button" name="button6" id="button6" onClick="location.href='Menu.php'" value="Cancel">
          ...
          <input type="button" name="button2" id="button2" value="Delete">
         ...
      <input type="button" name="button3" id="button3" value="Print Barcode"> </td>
    </tr>
  </table>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>

这是我的PHP脚本

<?
$conn = mysql_connect('localhost', 'root', 'root');
    if (!$conn)
    {
    die('Could not connect: ' . mysql_error());
   }
   mysql_select_db("LAC", $conn);

   $Barcode =$_REQUEST['barcode'];

$result = mysql_query("SELECT * FROM Lists WHERE Barcode  = '$Barcode'");
$row = mysql_fetch_array($result);
if (!$result)
      {
      die("Error: Data not found..");
      }
         $Barcode = $row['Barcode'];
         $Sponsor = $row['Sponsor'];
         $DateReceived = $row['DateReceived'];
         $Container = $row['Container'];
         $Pallet = $row['Pallet'];
         $Amount = $row['Amount'];
         $Description = $row['Description'];
         $Remarks = $row['Remarks'];
         $Location = $row['Location'];

mysql_close($conn);
?>

所以基本上我想在输入正确的条形码并点击搜索按钮时从数据库中加载所有文本框和下拉框。 出于某种原因,当我点击搜索按钮时,它不会加载它只是重新加载页面的任何东西。 我是php的新手,但在vb.net中有编程经验

1 个答案:

答案 0 :(得分:0)

我认为在PHP脚本中从数据库中获取值后,您正在初始化变量。所以这些变量的范围只与该文件有关。所以,我想如果你在modifyitem.php中包含该文件,这将有效。

谢谢你。