仅在表单的第一个字段中显示值,即使这些字段具有值,所有其他字段也显示为空白
我从mySql查询中获取了许多字段,但它只显示了第一个获取的字段,如果我将第一个获取字段的名称复制为表单所有输入框的值,则只显示第一个其他字段为空白。 当我回显这些列时,其他列显示值。
<!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>Library Information</title>
</head>
<body>
<?php
//include 'Header.php';
include 'AHome.php';
require_once("connect.inc.php");
$conn = mysqli_connect(HOST, DBUSER, PASS,DB) or die('Could not connect !<br />Please contact the site\'s administrator.');
$result = mysqli_query($conn,"SELECT NM , ADDRESS1 , ADDRESS2 , CITY , STATE , COUNTRY , PHONENO , FAXNO , EMAIL1 FROM library_info LIMIT 1 ");
if($result)
{
while($row = mysqli_fetch_array($result))
{
$Nm1 = $row['NM'];
$Add1 = $row['ADDRESS1'];
$Add2 = $row['ADDRESS2'];
$City = $row['CITY'];
$State = $row['STATE'];
$Country = $row['COUNTRY'];
$Phone = $row['PHONENO'];
$Fax = $row['FAXNO'];
$Email1 = $row['EMAIL1'];
echo $Add1;
echo "<form name='Lib-Info' id='Lib-Info' method='post' onsubmit='return validate()' action='LibInfo.php' >
<fieldset>
<legend>
Basic Information
</legend>
<dl>
<dt>
Name: <input tabindex='1' accesskey='n' name='Nm' type='text' maxlength='200' id='Nm' value = \"$Nm1\" />
</dt>
</dl>";
echo "<dl><dt>
Address Line 1 <input tabindex='2' accesskey='A' Name='Add1' type='text' maxlength='200' id='Add1' \"$Nm1\" />
</dt></dl>";
echo "<dl><dt>
Address Line 2 <input tabindex='3' accesskey='B' Name='Add2' type='text' maxlength='200' id='Add2' \"$Nm1\" />
</dt></dl>
<dl><dt>
City: <input tabindex='4' accesskey='C' Name='City' type='text' maxlength='50' id='City' \"$Nm1\" />
</dt></dl>
<dl><dt>
State <input tabindex='4' accesskey='S' Name='State' type='text' maxlength='200' id='State' \"$Nm1\" />
</dt></dl>
<dl><dt>
Country: <input tabindex='5' accesskey='B' Name='Country' type='text' maxlength='200' id='Country' \"$Nm1\" />
</dt></dl>
</fieldset>
<fieldset>
<legend>Contact Details</legend>
<dl><dt>
Contact No: <input tabindex='6' accesskey='P' Name='Phone' type='text' maxlength='200' id='Phone' \"$Nm1\" />
</dt></dl>
<dl><dt>
Fax No.: <input tabindex='7' accesskey='F' Name='Fax' type='text' maxlength='200' id='Fax' \"$Nm1\" />
</dt></dl>
<dl><dt>
E-Mail: <input tabindex='8' accesskey='E' Name='Email' type='text' maxlength='200' id='Email' \"$Nm1\" />
</dt></dl>
</fieldset>
<label title='Submit'>
<input tabindex='9' accesskey='l' type='submit' name='Submit' value='Submit' />
</label>
</form>";
}
}
else
{
die(mysqli_error($con));
}
include 'footer.php';?>
</body>
<script>
function validate()
{
var Nm = document.getElementById("Nm")
if(Nm.value=='')
{
alert("Library Name required");
return(false);
}
Nm = '';
Nm = document.getElementById("Add1");
if(Nm.value=='')
{
alert("Address Line 1 required");
return(false);
}
Nm = '';
Nm = document.getElementById("Phone");
if(Nm.value=='')
{
alert("Contact No. required");
return(false);
}
Nm = '';
Nm = document.getElementById("Email");
if(Nm.value=='')
{
alert("Mail address required");
return(false);
}
Nm = document.getElementById("");
if(Nm.value=='')
{
alert("Library Name Required");
return(false);
}
}
</script>
</html>
结果
答案 0 :(得分:0)
您错过了value =''参数,并且您出于某种原因尝试输出相同的$ NM1变量。将代码更改为:
<!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>Library Information</title>
</head>
<body>
<?php
//include 'Header.php';
include 'AHome.php';
require_once("connect.inc.php");
$conn = mysqli_connect(HOST, DBUSER, PASS,DB) or die('Could not connect !<br />Please contact the site\'s administrator.');
$result = mysqli_query($conn,"SELECT NM , ADDRESS1 , ADDRESS2 , CITY , STATE , COUNTRY , PHONENO , FAXNO , EMAIL1 FROM library_info LIMIT 1 ");
if ($result)
{
while($row = mysqli_fetch_array($result))
{
$Nm1 = $row['NM'];
$Add1 = $row['ADDRESS1'];
$Add2 = $row['ADDRESS2'];
$City = $row['CITY'];
$State = $row['STATE'];
$Country = $row['COUNTRY'];
$Phone = $row['PHONENO'];
$Fax = $row['FAXNO'];
$Email1 = $row['EMAIL1'];
echo $Add1;
echo "<form name='Lib-Info' id='Lib-Info' method='post' onsubmit='return validate()' action='LibInfo.php' >
<fieldset>
<legend>
Basic Information
</legend>
<dl>
<dt>
Name: <input tabindex='1' accesskey='n' name='Nm' type='text' maxlength='200' id='Nm' value = \"$Nm1\" />
</dt>
</dl>";
echo "<dl><dt>
Address Line 1 <input tabindex='2' accesskey='A' Name='Add1' type='text' maxlength='200' id='Add1' value=\"$Add1\" />
</dt></dl>";
echo "<dl><dt>
Address Line 2 <input tabindex='3' accesskey='B' Name='Add2' type='text' maxlength='200' id='Add2' value=\"$Add2\" />
</dt></dl>
<dl><dt>
City: <input tabindex='4' accesskey='C' Name='City' type='text' maxlength='50' id='City' value=\"$City\" />
</dt></dl>
<dl><dt>
State <input tabindex='4' accesskey='S' Name='State' type='text' maxlength='200' id='State' value=\"$State\" />
</dt></dl>
<dl><dt>
Country: <input tabindex='5' accesskey='B' Name='Country' type='text' maxlength='200' id='Country' value=\"$Country\" />
</dt></dl>
</fieldset>
<fieldset>
<legend>Contact Details</legend>
<dl><dt>
Contact No: <input tabindex='6' accesskey='P' Name='Phone' type='text' maxlength='200' id='Phone' value=\"$Phone\" />
</dt></dl>
<dl><dt>
Fax No.: <input tabindex='7' accesskey='F' Name='Fax' type='text' maxlength='200' id='Fax' value=\"$Fax\" />
</dt></dl>
<dl><dt>
E-Mail: <input tabindex='8' accesskey='E' Name='Email' type='text' maxlength='200' id='Email' value=\"$Email\" />
</dt></dl>
</fieldset>
<label title='Submit'>
<input tabindex='9' accesskey='l' type='submit' name='Submit' value='Submit' />
</label>
</form>";
}
}
else
{
die(mysqli_error($con));
}
include 'footer.php';?>
</body>
<script>
function validate()
{
var Nm = document.getElementById("Nm")
if(Nm.value=='')
{
alert("Library Name required");
return(false);
}
Nm = '';
Nm = document.getElementById("Add1");
if(Nm.value=='')
{
alert("Address Line 1 required");
return(false);
}
Nm = '';
Nm = document.getElementById("Phone");
if(Nm.value=='')
{
alert("Contact No. required");
return(false);
}
Nm = '';
Nm = document.getElementById("Email");
if(Nm.value=='')
{
alert("Mail address required");
return(false);
}
Nm = document.getElementById("");
if(Nm.value=='')
{
alert("Library Name Required");
return(false);
}
}
</script>
</html>
答案 1 :(得分:0)
我可以在这里看到两个问题
您可以尝试以下代码。
<!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>Library Information</title>
</head> <body>
<?php
//include 'Header.php';
include 'AHome.php';
require_once("connect.inc.php");
$conn = mysqli_connect(HOST, DBUSER, PASS, DB) or die('Could not connect !<br />Please contact the site\'s administrator.');
$result = mysqli_query($conn, "SELECT NM , ADDRESS1 , ADDRESS2 , CITY , STATE , COUNTRY , PHONENO , FAXNO , EMAIL1 FROM library_info LIMIT 1 ");
if ($result) {
while ($row = mysqli_fetch_assoc($result)) {
$Nm1 = $row['NM'];
$Add1 = $row['ADDRESS1'];
$Add2 = $row['ADDRESS2'];
$City = $row['CITY'];
$State = $row['STATE'];
$Country = $row['COUNTRY'];
$Phone = $row['PHONENO'];
$Fax = $row['FAXNO'];
$Email1 = $row['EMAIL1'];
echo $Add1;
?>
<form name='Lib-Info' id='Lib-Info' method='post' onsubmit='return validate()' action='LibInfo.php'>
<fieldset>
<legend>
Basic Information
</legend>
<dl>
<dt>
Name: <input tabindex='1' accesskey='n' name='Nm' type='text' maxlength='200' id='Nm'
value='<?php echo $Nm1 ?>'/>
</dt>
</dl>
<dl>
<dt>
Address Line 1 <input tabindex='2' accesskey='A' Name='Add1' type='text' maxlength='200'
id='Add1' value='<?php echo $Add1 ?>'/>
</dt>
</dl>
<dl>
<dt>
Address Line 2 <input tabindex='3' accesskey='B' Name='Add2' type='text' maxlength='200'
id='Add2' value='<?php echo $Add2 ?>' />
</dt>
</dl>
<dl>
<dt>
City: <input tabindex='4' accesskey='C' Name='City' type='text' maxlength='50' id='City' value='<?php echo $City ?>'
/>
</dt>
</dl>
<dl>
<dt>
State <input tabindex='4' accesskey='S' Name='State' type='text' maxlength='200' id='State' value='<?php echo $State ?>'
/>
</dt>
</dl>
<dl>
<dt>
Country: <input tabindex='5' accesskey='B' Name='Country' type='text' maxlength='200'
id='Country' value='<?php echo $Country ?>' />
</dt>
</dl>
</fieldset>
<fieldset>
<legend>Contact Details</legend>
<dl>
<dt>
Contact No: <input tabindex='6' accesskey='P' Name='Phone' type='text' maxlength='200'
id='Phone' value='<?php echo $Phone ?>' />
</dt>
</dl>
<dl>
<dt>
Fax No.: <input tabindex='7' accesskey='F' Name='Fax' type='text' maxlength='200' id='Fax' value='<?php echo $Fax ?>'
/>
</dt>
</dl>
<dl>
<dt>
E-Mail: <input tabindex='8' accesskey='E' Name='Email' type='text' maxlength='200' id='Email' value='<?php echo $Email1 ?>'
/>
</dt>
</dl>
</fieldset>
<label title='Submit'>
<input tabindex='9' accesskey='l' type='submit' name='Submit' value='Submit'/>
</label>
</form>
<?php
}
} else {
die(mysqli_error($con));
}
include 'footer.php'; ?>
</body>
<script>
function validate() {
var Nm = document.getElementById("Nm")
if (Nm.value == '') {
alert("Library Name required");
return (false);
}
Nm = '';
Nm = document.getElementById("Add1");
if (Nm.value == '') {
alert("Address Line 1 required");
return (false);
}
Nm = '';
Nm = document.getElementById("Phone");
if (Nm.value == '') {
alert("Contact No. required");
return (false);
}
Nm = '';
Nm = document.getElementById("Email");
if (Nm.value == '') {
alert("Mail address required");
return (false);
}
Nm = document.getElementById("");
if (Nm.value == '') {
alert("Library Name Required");
return (false);
}
}
</script>
</html>