2017-02-16 48 views
-1

只是形式上的所有其他領域的第一場顯示值顯示空白,即使這些字段具有值僅顯示在HTML表單首先取指令字段

我已經賺得一些領域從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> 

結果

Output of Code

+0

您面臨的問題是什麼。 –

+0

您錯過了每個輸入標籤上的屬性'value'和變量的名稱應該是相關的。 – C2486

回答

0

你錯過了價值= '' 參數,你正試圖輸出由於某種原因在同一$ 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> 
0

我可以看到這裏有兩個問題

  1. 一個是你使用mysqli_fetch_array。其實你需要使用mysqli_fetch_assoc
  2. 在每個輸入字段中缺少值屬性。

您可以嘗試下面的代碼。

<!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> 
相關問題