2012-12-01 33 views
0

我正在一個網站上課,我有一個表單系統。我的朋友正在設計,因此指數的網站實際上只是這樣的:PHP回聲,清除我周圍的HTML?

<!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=iso-8859-1" /> 
<title>Nail n' Bolts man</title> 
<link href="../../styles/main.css" rel="stylesheet" type="text/css" /> 
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
<script type="text/javascript" src="../../js/main.js"></script> 
</head> 

<body> 

    <div id="main"> 
     <center> 
      <div id="header"> 
       Nails & Bolts APS - Admin side 
       <img src="../images/header.jpg" alt="header" width="" height="" /> 
      </div> 

      <?php require('php/newEmployee.php'); ?> 
     </center> 
    </div> 

</body> 
</html> 

然後在newEmployee.php我還需要一種叫varibleEcho.php另一個文件基本上這個文件只是有一個開關盒的功能聲明,迴應不同的代碼,這取決於你從newEmployee.php調用的內容

但是,由於某種原因,當我用谷歌瀏覽器檢查網站的源代碼時,似乎回顯會清除除我回應的東西外的所有內容。這意味着我的元數據css jquery和這樣的dissapers。

爲什麼它有這種行爲的任何想法?

編輯:

這裏是整個網站(indes.php那裏):

newEmployee.php

<?php 
require('php/variableEcho.php'); 
    if(!isset($_POST['rank']) || !isset($_POST['fname']) || !isset($_POST['lname']) || !isset($_POST['initials'])) 
    { 
     variableEcho(0); 
     variableEcho(1);  
    } 
    else if($_POST['rank'] == '' || $_POST['fname'] == '' || $_POST['lname'] == '' || $_POST['initials'] == '') 
    { 
     variableEcho(0); 
     variableEcho(3); 
     variableEcho(1); 
    } 
     else if($_POST['password'] != '') 
    { 
    echo $_POST['password']; 
    $hasLetter = false; 
    $hasNumber = false; 
    $hasLength = false; 

    $pwd = $_POST['password']; 

    $strlen = strlen($pwd); 
    $pwdarr = str_split($pwd); 

    $ints = 0; 
    $chars = 0; 
    foreach($pwdarr as $x) 
    { 
     if(is_int($x)) 
     { 
      $ints++; 
     } 
     if(ctype_alpha($x)) 
     { 
      $chars++; 
     } 
    } 
    if($ints >= $strlen || $chars >= $strlen) 
    { 
     variableEcho(0); 
     variableEcho(4); 
     variableEcho(1); 
    } 

    if($strlen >= 8) 
    { 
     variableEcho(0); 
     variableEcho(4); 
     variableEcho(1); 
    } 
} 
?> 

variableEcho

<?php 
function variableEcho($echoSelect) 
{ 
    switch($echoSelect) 
    { 
     case 0: 
      echo(' 
       <form action="" method="post"> 
        <table> 
      '); 
      break; 

     case 1: 
      echo(' 
         <tr> 
          <td><label for="fname">First name*</label></td> 
          <td><input type="text" name="fname" id="fname"/></td> 
         </tr> 
         <tr> 
          <td><label for="lname">Last name*</label></td> 
          <td><input type="text" name="lname" id="lname"/></td> 
         </tr> 
         <tr> 
          <td><label for="rank">Rank*</label></td> 
          <td><input type="text" name="rank" id="rank"/></td> 
         </tr> 
         <tr> 
          <td><label for="initials">Initials (3 length)*</label></td> 
          <td><input type="text" name="initials" id="initials"/></td> 
         </tr> 
         <tr> 
          <td><label for="password">Password</label></td> 
          <td><input type="text" name="password" id="password"/></td> 
         </tr> 
         <tr> 
         <td><input type="submit"/></td> 
        </form> 
      '); 
      break; 

     case 2: 
      echo(' 
         <tr> 
          <td><div class="errText">A password is required for admins.</div></td> 
          <td></td> 
         </tr> 
      '); 
      break; 

     case 3: 
      echo(' 
         <tr> 
          <td><div class="errText">Please fill out all the obligatory fields.</div></td> 
          <td></td> 
         </tr> 
      '); 

     case 4: 
      echo(' 
         <tr> 
          <td><div class="errText">The password need to be of atleas one letter, one number, and 8 long.</div></td> 
          <td></td> 
         </tr> 

      '); 
      break; 

     default: 
      echo(' 
       biscuit 
      '); 
      break; 
    } 
} 

?> 
+0

我不知道是什麼原因造成的,但可以通過刪除大部分代碼(並驗證問題不再發生)並慢慢添加,直到問題恢復爲止。另外,您在案例3中沒有休息。在默認情況下,您不需要休息。 – sachleen

+0

我假設有人提交表單後問題發生,如果是這樣的話,請檢查瀏覽器中的URL是什麼,並確保它是應該的,你在表單上留下了'action'屬性爲空 –

+0

動作爲空,因爲它應該發送給自己。我向站點回復不同的內容,具體取決於輸入,因此也在默認站點上。 – Dumle29

回答

0

我想通出了我的問題,這是一個簡單的問題:P

require'newEmployee.php';

會包含該php文件。在那個文件中,我需要另一個文件路徑與newEmployee.php locaiton相關的文件路徑。我現在改爲在主文件中包含variableEcho和newEmployee。

<?php 
    require('../../php/variableEcho.php'); 
    require('../../php/newEmployee.php');    
?>