将文本区域数据从MySQL拉取到现有的HTML表单中


Pulling Text Area Data from MySQL into existing HTML Form

我有一个我创建的供内部使用的表单。 我已经能够用表单中的数据填充MySQL数据库。 我还创建了一个搜索功能,该函数将根据ID键(在本例中为数字)将数据拉回字段中。 所有文本字段都会返回到字段中,但文本区域数据不会。 我转到MySQL数据库,并填写了这些文本区域的表字段,但它们似乎没有拉回表单。 如果可以的话,请帮助我。 谢谢。

我的 HTML 表单:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>- - = =  EPC Print Order Form = = - -  </title>
</head>
<body bgcolor="#DFDFD9">
<h1>Digital Print Form &nbsp &nbsp<input type="image" src="http://commonmedia.asicentral.com/180000/182101/EPC_KAPP.jpg"></h1>
<!-- form to get key detail of record in database -->
<fieldset style='width:570px; text-align:left; border-width:2px;'>
<legend><h3>Request RFQ</h3></legend>
<table bgcolor="beige" border="0" width="570px">
<tr>
<td><form name="form" method="POST" action="form1.php">
RFQ#:</td><td><input type="text" name="search"></td><td><input type="submit"  value="submit"></td>
</form></tr></table>
</fieldset>
<!---------------------  Print Form Data ------------------>
<form action="mysqlTest.php" method="post" id="prayfrm" name="prayfrm" onsubmit="return checkform(this);" onreset="return confirm('Do you want to clear this form?')">
<input type="hidden" name="drfq" value="6">
<!--**********   Basic Job Information for the form******************-->
<fieldset style='width:570px; text-align:left; border-width:2px;'>
<legend><h3>Job Information</h3></legend>
<table bgcolor="beige" border="0" width="570px">
<tr>
        <td><label for="drepid">Sales Rep</label></td>
        <td><input type="text" name="drepid" size="30" required="true"/>
        </td>
        <td><label>Today's Date</label></td>
<td><input type="text" name="datepicker" size="10"/></td>
</tr>     
<tr>
<td><label for="repemail">Rep Email</label></td>
<td><input id="repemail" name="repemail" type="text" size="30" required="true" /></td>
<td><label>Date Needed</label></td>
<td><input id="dateneeded" name="dateneeded" type="text" size="10" required="true" /> </td>
</tr>
<tr>
<td><label for="description">Description</label></td>
<td><input id="description" name="description" type="text" size="30" required="true" /></td>
<td><label for="qty">Quantity</label></td>
<td><input id="qty" name="qty" type="text" size="10" required="true" /></td>
</tr>
<tr>
<td><label for="pgsizeh">Page Size (h) x (w)</label></td>
<td><input id="pgsizeh" name="pgsizeh" type="text" size="10" required="true" />  x  <input id="pgsizew" name="pgsizew" type="text" size="13" required="true" /></td>
<td><label for="pageno">Page Number</label></td>
<td><input id="pageno" name="pageno" type="text" size="10" required="true" /></td>
</tr>
<tr>
<td><label for="stock">Stock</label></td>
<td><input id="stock" name="stock" type="text" size="10" required="true" /> &nbsp<label for="stock">Color &nbsp </label>
<input type="text" name="ink" size="6" required="true"/>
</td>
<td><label for="inknote"> &nbsp Explain </label></td>
<td><input id="inknote" name="inknote" type="text" size="10" /></td>                    
</tr>
<tr>
<td><label for="rfq">Referenced RFQ:</label></td>
<td><input id="rfq" name="rfq" type="text" size="10" required="true" /><td><label for="finishing">Finishing</label></td>
<td><input id="finishing" name="finishing" type="text" size="10" required="true" />
</tr>
</table></fieldset>
<!--**********  Customer Information for the form******************-->
<fieldset style='width:570px; text-align:left; border-width:2px;'>
<legend><h3>Customer Information</h3></legend>
<table bgcolor="beige" border="0" width="570px">
<tr>
<td><label for="dfirstname">First Name</label></td><td><input id="dfirstname" name="dfirstname" type="text" size="31" required="true" /></td><td><label for="dlastname">&nbsp Last </label></td><td><input id="dlastname" name="dlastname" type="text" size="31" required="true" /></td>
</tr>
<tr>
<td><label for="dorganization">Organization</label></td>
<td><input id="dorganization" name="dorganization" type="text" size="31" required="true" /></td><td><label for="email">Email</label></td>
<td><input id="email" name="email" type="text" size="31" required="true" /></td>
</tr>
<tr>
<td><label for="daddress1">Address</label></td><td><input id="daddress1" name="daddress1" type="text" size="31" required="true" /><td></td><td><input id="daddress2" name="daddress2" type="text" size="31" />
</tr>
<tr>
<td><label for="dcity">City</label></td><td><input id="dcity" name="dcity" type="text" size="25" required="true" /> <label for="dstate"> State</label></td><td><input id="dstate" name="dstate" type="text" size="3" required="true" /> <td><label for="dzip"> Zip </label> <input id="dzip" name="dzip" type="text" size="27" required="true" /></tr>
<tr>
<td><label for="phone">Phone </label><td><input id="phone" name="phone" type="text" size="31" required="true" /></td><td><label for="fax">Fax </label><td><input id="fax" name="fax" type="text" size="31" required="true" /> </td>
</tr></table></fieldset>
<!--**********  Delivery Information for the form******************-->
<fieldset style='width:570px; text-align:left; border-width:2px;'>
<legend><h3>Delivery Information</h3></legend>
<table bgcolor="beige" border="0" width="570px">
<tr>
<td><label for="proof">Proof?</label>&nbsp <input type="checkbox" name="proof" value="yes"  required="true" />&nbsp </td><td><label for="whoproof">Proof to Whom?</label> <input id="whoproof" name="whoproof" type="text" size="44" required="true" /></td>
</tr>
<tr>
<td><label for="quote">Quote?</label>&nbsp<input type="checkbox" name="quote" value="yes" required="true" />&nbsp </td>
<td><label for="amount">Amount: $</label> <input id="amount" name="amount" type="text" size="50" required="true" /></td>
</tr>
<tr>
<td><label for="delivery">Delivery Instructions</label></td><td><textarea name="delivery" rows="4" cols="50"></textarea></tr>
<tr>
<td><label for="notes">Additional Notes</label></td><td><textarea name="notes" rows="4" cols="50"></textarea>
</tr>
<td align="right"><input name="submit" type="submit" id="submit" value="Submit" /></td>
<td align="left"><input name="Reset" type="reset" id="reset" value="Reset Form" /></table></fieldset>
</body>
</html>

我的 PHP 文件,用于将字段添加到数据库

<?php
$dbhost = 'hostname';
$dbuser = 'username';
$dbpass = '*******';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 'dbasename';
mysql_select_db($dbname);
// -------------------------------------------------------------------
// Field Names
// -------------------------------------------------------------------
$drepid=mysql_real_escape_string($_POST['drepid']);
$datepicker=mysql_real_escape_string($_POST['datepicker']);
$repemail=mysql_real_escape_string($_POST['repemail']);
$dateneeded=mysql_real_escape_string($_POST['dateneeded']);
$description=mysql_real_escape_string($_POST['description']);
$qty=mysql_real_escape_string($_POST['qty']);
$pgsizeh=mysql_real_escape_string($_POST['pgsizeh']);
$pgsizew=mysql_real_escape_string($_POST['pgsizew']);
$pageno=mysql_real_escape_string($_POST['pageno']);
$stock=mysql_real_escape_string($_POST['stock']);
$ink=mysql_real_escape_string($_POST['ink']);
$inknote=mysql_real_escape_string($_POST['inknote']);
$rfq=mysql_real_escape_string($_POST['rfq']);
$finishing=mysql_real_escape_string($_POST['finishing']);
$dfirstname=mysql_real_escape_string($_POST['dfirstname']);
$dlastname=mysql_real_escape_string($_POST['dlastname']);
$dorganization=mysql_real_escape_string($_POST['dorganization']);
$email=mysql_real_escape_string($_POST['email']);
$daddress1=mysql_real_escape_string($_POST['daddress1']);
$daddress2=mysql_real_escape_string($_POST['daddress2']);
$dcity=mysql_real_escape_string($_POST['dcity']);
$dstate=mysql_real_escape_string($_POST['dstate']);
$dzip=mysql_real_escape_string($_POST['dzip']);
$phone=mysql_real_escape_string($_POST['phone']);
$fax=mysql_real_escape_string($_POST['fax']);
$proof=mysql_real_escape_string($_POST['proof']);
$whoproof=mysql_real_escape_string($_POST['whoproof']);
$quote=mysql_real_escape_string($_POST['quote']);
$amount=mysql_real_escape_string($_POST['amount']);
$delivery=mysql_real_escape_string($_POST['delivery']);
$notes=mysql_real_escape_string($_POST['notes']);
$sql = "INSERT INTO epc_print (drepid, datepicker, repemail, dateneeded, description, qty, pgsizeh, pgsizew, pageno, stock, ink, inknote, rfq, finishing, dfirstname, dlastname, dorganization, email, daddress1, daddress2, dcity, dstate, dzip, phone, fax, proof, whoproof, quote, amount, delivery, notes) values ('$drepid', '$datepicker', '$repemail', '$dateneeded', '$description', '$qty', '$pgsizeh', '$pgsizew', '$pageno', '$stock', '$ink', '$inknote', 'rfq', '$finishing', '$dfirstname', '$dlastname', '$dorganization', '$email', '$daddress1', '$daddress2', '$dcity', '$dstate', '$dzip', '$phone', '$fax', '$proof', '$whoproof', '$quote', '$amount', '$delivery', '$notes')";
mysql_query($sql) or die(mysql_error());
echo "
<code><pre></code>";
echo "POST:";
print_r($_POST);
echo "<code></pre></code>
";
echo "1 record added";

?>

然后我的php文件来检索数据:

<?php
$connection = mysql_connect('hostname','username','*****') or die ("Couldn't connect to server."); 
$db = mysql_select_db('databasename', $connection) or die ("Couldn't select database."); 
$search=$_POST['search'];
$data = 'SELECT * FROM `epc_print` WHERE `drfq` = "'.$search.'"';
  $query = mysql_query($data) or die("Couldn't execute query. ". mysql_error());
  $data2 = mysql_fetch_array($query);

?> 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
      <title>- - = = EPC Print Form = = - - </title>
 </head>
<body bgcolor="#DFDFD9">
<h1>Digital Print Form &nbsp &nbsp<input type="image" src="http://commonmedia.asicentral.com/180000/182101/EPC_KAPP.jpg"></h1>
<!-- form to get key detail of record in database -->
<fieldset style='width:570px; text-align:left; border-width:2px;'>
<legend><h3>Request RFQ</h3></legend>
<table bgcolor="beige" border="0" width="570px">
<tr>
<td><form name="form" method="POST" action="form1.php">
RFQ#:</td><td><input type="text" name="search"></td><td><input type="submit"  value="submit"></td>
</form></tr></table>
</fieldset>
<!---------------------  Print Form Data ------------------>
<form action="form2.php" method="post" id="prayfrm" name="prayfrm" onsubmit="return checkform(this);" onreset="return confirm('Do you want to clear this form?')">
<input type="hidden" name="drfq" value="6">
<!--**********   Basic Job Information for the form******************-->
<fieldset style='width:570px; text-align:left; border-width:2px;'>
<legend><h3>Job Information</h3></legend>
<table bgcolor="beige" border="0" width="570px">
<tr>
        <td><label for="drepid">Sales Rep</label></td>
        <td><input id="drepid" name="drepid" type="text" size="30" value="<?php echo htmlspecialchars ($data2[drepid])?>" required="true" /></td>

      </td>
        <td><label>Today's Date</label></td>
<td><input id="datepicker" name="datepicker" type="text" size="10" value="<?php echo htmlspecialchars ($data2[datepicker])?>" required="true" /></td>
</tr>     
<tr>
<td><label for="repemail">Rep Email</label></td>
<td><input id="repemail" name="repemail" type="text" size="30" value="<?php echo htmlspecialchars ($data2[repemail])?>" required="true" /></td>
<td><label>Date Needed</label></td>
<td><input id="dateneeded" name="dateneeded" type="text" size="10" value="<?php echo htmlspecialchars ($data2[dateneeded])?>" required="true" /></td></td>
</tr>
<tr>
<td><label for="description">Description</label></td>
<td><input id="description" name="description" type="text" size="30" value="<?php echo htmlspecialchars ($data2[description])?>" required="true" /></td>
<td><label for="qty">Quantity</label></td>
<td><input id="qty" name="qty" type="text" size="10" value="<?php echo htmlspecialchars ($data2[qty])?>"required="true" /></td>
</tr>
<tr>
<td><label for="pgsizeh">Page Size (h) x (w)</label></td>
<td><input id="pgsizeh" name="pgsizeh" type="text" size="10" value="<?php echo htmlspecialchars ($data2[pgsizeh])?>" required="true" />  x  <input id="pgsizew" name="pgsizew" type="text" size="14" value="<?php echo  htmlspecialchars ($data2[pgsizew])?>" required="true" /></td>
<td><label for="pageno">Page Number</label></td>
<td><input id="pageno" name="pageno" type="text" size="10" value="<?php echo htmlspecialchars ($data2[pageno])?>" required="true" /></td>
</tr>
<tr>
<td><label for="stock">Stock</label></td>
<td><input id="stock" name="stock" type="text" size="10" value="<?php echo htmlspecialchars ($data2[stock])?>" required="true" /> <label for="ink">Color </label> <input id="ink" name="ink" type="text" size="10" value="<?php echo htmlspecialchars ($data2[ink])?>" required="true" /></td>
<td><label for="inknote"> &nbsp Explain </label></td>
<td><input id="inknote" name="inknote" type="text" size="10" value="<?php echo htmlspecialchars ($data2[inknote])?>"/></td>                 
</tr>
<tr>
<td><label for="rfq">Referenced RFQ:</label></td>
<td><input id="rfq" name="rfq" type="text" size="10" value="<?php echo htmlspecialchars ($data2[rfq])?>" required="true"/></td> <td><label for="finishing">Finishing</label></td>
<td><input id="finishing" name="finishing" type="text" size="10" value= "<?php echo htmlspecialchars ($data2[finishing])?>" required="true" />
</tr>
</table></fieldset>
<!--**********  Customer Information for the form******************-->
<fieldset style='width:570px; text-align:left; border-width:2px;'>
<legend><h3>Customer Information</h3></legend>
<table bgcolor="beige" border="0" width="570px">
<tr>
<td><label for="dfirstname">First Name</label></td><td><input id="dfirstname" name="dfirstname" type="text" size="31" value="<?php echo htmlspecialchars ($data2[dfirstname])?>" required="true" /></td><td><label for="dlastname">&nbsp Last </label></td><td><input id="dlastname" name="dlastname" type="text" size="31" value= "<?php echo htmlspecialchars ($data2[dlastname])?>"required="true" /></td>
</tr>
<tr>
<td><label for="dorganization">Organization</label></td>
<td><input id="dorganization" name="dorganization" type="text" size="31" value="<?php echo htmlspecialchars ($data2[dorganization])?>" required="true" /></td><td><label for="email">Email</label></td>
<td><input id="email" name="email" type="text" size="31" value="<?php echo htmlspecialchars ($data2[email])?>" required="true" /></td>
</tr>
<tr>
<td><label for="daddress1">Address</label></td><td><input id="daddress1" name="daddress1" type="text" size="31" value="<?php echo htmlspecialchars ($data2[daddress1])?>" required="true" /><td></td><td><input id="daddress2" name="daddress2" type="text" size="31" value="<?php echo htmlspecialchars ($data2[daddress2])?>"/>
</tr>
<tr>
<td><label for="dcity">City</label></td><td><input id="dcity" name="dcity" type="text" size="25" value="<?php echo htmlspecialchars ($data2[dcity])?>" required="true" /> <label for="dstate"> State</label></td><td><input id="dstate" name="dstate" type="text" size="3" value="<?php echo htmlspecialchars ($data2[dstate])?>" required="true" /> <td><label for="dzip"> Zip </label> <input id="dzip" name="dzip" type="text" size="27" value="<?php echo htmlspecialchars ($data2[dzip])?>" required="true" /></tr>
<tr>
<td><label for="phone">Phone </label><td><input id="phone" name="phone" type="text" size="31" value="<?php echo htmlspecialchars ($data2[phone])?>" required="true" /></td><td><label for="fax">Fax </label><td><input id="fax" name="fax" type="text" size="31" value="<?php echo htmlspecialchars ($data2[fax])?>"/> </td>
</tr></table></fieldset>
<!--**********  Delivery Information for the form******************-->
<fieldset style='width:570px; text-align:left; border-width:2px;'>
<legend><h3>Delivery Information</h3></legend>
<table bgcolor="beige" border="0" width="570px">
<tr>
<td><label for="proof">Proof?</label>&nbsp <input type="checkbox" name="proof" value="<?php echo ($data2[proof])?>" />&nbsp </td><td><label for="whoproof">Proof to Whom?</label> <input id="whoproof" name="whoproof" type="text" size="44" value="<?php echo htmlspecialchars ($data2[whoproof])?>"required="true" /></td>
</tr>
<tr>
<td><label for="quote">Quote?</label>&nbsp<input type="checkbox" name="quote" value="<?php echo htmlspecialchars ($data2[quote])?>" required="true" />&nbsp </td>
<td><label for="amount">Amount: $</label> <input id="amount" name="amount" type="text" size="50" value="<?php echo htmlspecialchars ($data2[amount])?>" required="true" /></td>
</tr>
<tr>
<td><label for="delivery">Delivery Instructions</label></td><td><textarea name="delivery" rows="4" cols="50" value="<?php echo htmlspecialchars ($data2[delivery])?>" /></textarea></tr>
<tr>
<td><label for="notes">Additional Notes</label></td><td><textarea name="notes" rows="4" cols="50" value="<?php echo htmlspecialchars ($data2[notes])?>"/></textarea>
</tr>
<td align="right"><input name="submit" type="submit" id="submit" value="Submit" /></td>
<td align="left"><input name="Reset" type="reset" id="reset" value="Reset Form" /></table></fieldset>
</body>
</html>

文本区域的默认值由元素内的文本节点提供,而不是 value 属性。

<textarea>Default value
Which can have new lines</textarea>

value 不是文本区域的有效属性,您需要使用 <textarea>value</textarea>