2016-03-07 78 views
-5

我得到一個語法錯誤語法簡單PHP的錯誤

Parse error: syntax error, unexpected 'text' (T_STRING) in C:... line 18.

我並不確切地知道爲什麼我收到這個錯誤。反應越快越好。非常感謝你。

<?php 
session_start(); 
?> 
<!doctype html> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
    <title>Login</title> 
</head> 
    <body> 
     <div align="center"> 
      <img src="logo.png" alt="school logo"> 
      <h2>login</h2> 
      <?php 
      $form="<form action='./login.php' method='post'> 
      <table> 
      <tr> 
       <td>Email:</td> 
       <td>input type="text" name:"Email"/></td> 
      </tr> 
      <tr> 
       <td>Password:</td> 
       <td><input type="text" name:"Password"/></td> 
      </tr> 
      <tr> 
       <td><</td> 
       <td><input type="submit" name="loginbtn" value="login"/></td> 
      </tr> 
      </table> 
      </form>"; 

      if ($_POST['loginbtn']){ 
       $email=$_POST["email"]; 
       $Password=$_POST["Password"]; 

       if($email){ 
        if($Password){ 
        } 
        else 
         echo"you must enter your password .$form"; 
       } 
       else 
        echo "you must enter your email .$form"; 

      } 
      else 
       echo""; 
      ?> 
     </div> 
    </body> 
</html> 
+1

http://stackoverflow.com/questions/ 3446216 /在單引號和雙引號字符串之間的區別是什麼php –

+0

嘗試重寫問題以包含您嘗試的內容,您認爲正在發生的事情以及小的(最小的)代碼示例,重新產生您的問題。 – mprat

+0

你忘記了你的開放和關閉標籤的PHP。 – SZenC

回答

1

試試這個

<?php 
session_start(); 
?> 
<!doctype html> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
    <title>Login</title> 
</head> 
    <body> 
     <div align="center"> 
      <img src="logo.png" alt="school logo"> 
      <h2>login</h2> 
      <?php 
      $form="<form action='./login.php' method='post'> 
      <table> 
      <tr> 
       <td>Email:</td> 
       <td>input type='text' name:'Email'/></td> 
      </tr> 
      <tr> 
       <td>Password:</td> 
       <td><input type='text' name:'Password'/></td> 
      </tr> 
      <tr> 
       <td><</td> 
       <td><input type='submit' name='loginbtn' value='login'/></td> 
      </tr> 
      </table> 
      </form>"; 

      if ($_POST['loginbtn']){ 
       $email=$_POST["email"]; 
       $Password=$_POST["Password"]; 

       if($email){ 
        if($Password){ 
        } 
        else 
         echo"you must enter your password .$form"; 
       } 
       else 
        echo "you must enter your email .$form"; 

      } 
      else 
       echo""; 
      ?> 
     </div> 
    </body> 
</html> 

變化雙柱單柱

+0

非常感謝。 – srhgrsdhfdh

1

你需要逃避你的HTML的"

$form="<form action='./login.php' method='post'> 
      <table> 
      <tr> 
       <td>Email:</td> 
       <td>input type=\"text\" name:\"Email\"/></td> 
      ... 
      </form>"; 
+0

非常感謝你 – srhgrsdhfdh

0

這樣做的最簡單的方法是如下:

<?php 
session_start(); 
?> 
<!doctype html> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
    <title>Login</title> 
</head> 
    <body> 
     <div align="center"> 
      <img src="logo.png" alt="school logo"> 
      <h2>login</h2> 
      <?php 
      if (isset($_POST['loginbtn'])){ //Use isset otherwise you may get undefined variable errors 
       $email=$_POST["email"]; 
       $Password=$_POST["Password"]; 
       if(!empty($email) || !empty($Password)) //If you use !$email and the variable isn't set, you get a warning. 
       { 
        if(!empty($email)) //Empty checks if it exists + has a value 
         echo "you must enter your password<br />"; //Must add a new line with <br /> 
        if(!empty($Password)) 
         echo "you must enter your email <br />"; 
        ?> 
        <form action='./login.php' method='post'> 
         <table> 
          <tr> 
           <td>Email:</td> 
           <td>input type="text" name:"Email"/></td> 
          </tr> 
          <tr> 
           <td>Password:</td> 
           <td><input type="text" name:"Password"/></td> 
          </tr> 
          <tr> 
           <td><</td> 
           <td><input type="submit" name="loginbtn" value="login"/></td> 
          </tr> 
         </table> 
        </form> 
        <?php 
       } 
      } 
      ?> 
     </div> 
    </body> 
</html> 

它修復的問題一樣:

  • 你的語法問題
  • 不需要投入大量的字符串中的HTML
  • 使用修復任何可能的未定義索引0或empty
  • 凝聚代碼,使閱讀更容易。
+0

非常感謝你 – srhgrsdhfdh

0

您已使用double-qoute(「」)爲$ form賦值。所以,你最好應在側it.Like使用單qoute:

$form="<form action='./login.php' method='post'> 
        <table> 
        <tr> 
         <td>Email:</td> 
         <td>input type='text' name:'Email'/></td> 
        </tr> 
        <tr> 
         <td>Password:</td> 
         <td><input type='text' name:'Password'/></td> 
        </tr> 
        <tr> 
         <td><</td> 
         <td><input type='submit' name='loginbtn' value='login'/></td> 
        </tr> 
        </table> 
        </form>"; 

或者您可以通過使用逃生繩一樣使用雙引號:

$form="<form action='./login.php' method='post'> 
     <table> 
     <tr> 
      <td>Email:</td> 
      <td>input type=\"text\" name:\"Email\"/></td> 
     </tr> 
     <tr> 
      <td>Password:</td> 
      <td><input type=\"text\" name:\"Password\"/></td> 
     </tr> 
     <tr> 
      <td><</td> 
      <td><input type=\"submit\" name=\"loginbtn\" value=\"login\"/></td> 
     </tr> 
     </table> 
     </form>"; 
+0

非常感謝 – srhgrsdhfdh