2012-08-17 105 views
1

无论我在两种情况下是否输入bug id的值,php标记之间的代码都显示为输出。有人能帮我找出原因吗? 代码如下:将html表单值传递给php文件

html文件-------------------------------------- -----------------------

<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title>Bug Report</title> 
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
</head> 
<body> 
<h2>Bug Report</h2> 
<form action="test.php" method="post" > 
<p>Bug ID:<input type="text" name="bugid" size="20" /></p>  
<p><input type="submit" value="Record Bug" /></p> 
</form> 
</body> 
</html> 

php file ------------------ --------------------------------

<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title>Record Bug</title> 
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
</head> 
<body> 

<?php 
       $bugid=$_POST["bugid"]; 
       echo $bugid; 
if (empty($bugid)) 
    { 
      echo "<p>You must enter the Bug ID to record the bug.</p>"; 
    }  
else 
    { 
    echo"<p>good</p>";   
        } 
?> 


</body> 
</html> 
+1

你是说if和else条件都正在执行,还是你说实际的PHP代码出现在页面上? – j08691 2012-08-17 03:34:59

+0

输出是:您必须输入Bug ID才能记录错误。 “;}其他{回声” 好 “;}?> – xing 2012-08-17 03:36:43

+0

你的代码是广泛开放的sql-禁制令 – 2012-08-17 03:45:17

回答

1
  1. 检查运行PHP是工作或没有为写代码<?php phpinfo(); ?>如果已经手动安装了PHP的Apache和获取问题尝试wamp server

  2. 你的代码是广泛开放SQL的禁令,以确保安全使用


public function mysql_prep($value) { 
     $magic_quotes_active = get_magic_quotes_gpc(); 
     $new_enough_php = function_exists("mysql_real_escape_string"); // i.e. PHP >= v4.3.0 
     if($new_enough_php) { // PHP v4.3.0 or higher 
      // undo any magic quote effects so mysql_real_escape_string can do the work 
      if($magic_quotes_active) { $value = stripslashes($value); } 
      $value = mysql_real_escape_string($value); 
     } else { // before PHP v4.3.0 
      // if magic quotes aren't already on then add slashes manually 
      if(!$magic_quotes_active) { $value = addslashes($value); } 
      // if magic quotes are active, then the slashes already exist 
     } 
     return $value; 
    } 
2

如果您在输出中获得PHP代码,那么您的网络服务器不会通过PHP解释器运行该页面/脚本。通常,这是因为您已将代码放入.html文件中,默认情况下,该文件不被视为PHP。

将文件重命名为whatever.php,或重新配置Web服务器以将.html文件作为PHP脚本对待。

+0

我重命名了该文件,但仍然与上面的输出相同 – xing 2012-08-17 03:40:26

+1

然后你应该检查为什么你的web服务器根本不运行PHP脚本 – 2012-08-17 03:44:56

0

在你到服务器,该服务器支持PHP像XAMPP或WAMP和运行情况也文件的扩展名应该是.PHP

1

检查PHP是否在你的机器运行与否。保存下面的代码为test.php的,并通过

<?php 

    phpinfo(); 

?> 
+0

我试过了,没有显示任何内容..空白页 – xing 2012-08-17 03:44:04

+3

然后你有PHP的问题。 – j08691 2012-08-17 03:45:02