简体   繁体   English

将html表单值传递给php文件

[英]Passing html form values to php file

Whether I enter the value for bug id or not ..in both conditions the code between php tags is displayed as output. 我是否输入了bug id的值。在这两种情况下,php标签之间的代码都显示为输出。 Can someone help me to find out the reason. 有人可以帮我找出原因。 Code is given below: 代码如下:

html file------------------------------------------------------------- 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-------------------------------------------------- php文件------------------------------------------------ -

<!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>

If you're getting PHP code in the output, then your webserver isn't running that page/script through the PHP interpreter. 如果您在输出中获得PHP代码,那么您的Web服务器不会通过PHP解释器运行该页面/脚本。 Generally, that's because you've put the code into a .html file, which is not treated as PHP by default. 通常,这是因为您已将代码放入.html文件中,默认情况下不会将其视为PHP。

Either rename the file to whatever.php , or reconfigure your webserver to treat .html files as PHP scripts. 将文件重命名为whatever.php ,或重新配置您的Web服务器以将.html文件视为PHP脚本。

Check whether php is running or not in your machine. 检查您的计算机中是否正在运行php。 Save the below code as test.php and run it through 将以下代码保存为test.php并运行它

<?php

   phpinfo();

?>
  1. check that php is working or not for that write the code <?php phpinfo(); ?> 检查php是否正常工作,编写代码<?php phpinfo(); ?> <?php phpinfo(); ?> and if have manually installed php apache and getting problem try wamp server <?php phpinfo(); ?>如果手动安装了php apache并且遇到问题请尝试使用wamp服务器

  2. your code is widely open for sql-injunction to make it secure use 您的代码广泛用于sql-prohibunction以使其安全使用


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;
    }

在这种情况下,您必须在支持PHP的服务器上运行,如Xampp或Wamp,并且文件的扩展名应为.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM