使用引导时PHP文件不工作
我是编程新手,因此需要一些帮助。下面是我使用Bootstrap为联系人表单编写的代码,但我的PHP代码似乎不起作用。 我一直将“index.php”文件与引导程序的其他文件一起保存。但是当我运行这个程序时,它会显示一个错误并且不会运行。 当我将此文件保存为“index.html”时,代码的html部分会运行,但PHP文件不会运行。 为了在wamp服务器中运行PHP文件,我应该将文件保存在Bootstrap还是wamp中使用引导时PHP文件不工作,php,html,Php,Html,我是编程新手,因此需要一些帮助。下面是我使用Bootstrap为联系人表单编写的代码,但我的PHP代码似乎不起作用。 我一直将“index.php”文件与引导程序的其他文件一起保存。但是当我运行这个程序时,它会显示一个错误并且不会运行。 当我将此文件保存为“index.html”时,代码的html部分会运行,但PHP文件不会运行。 为了在wamp服务器中运行PHP文件,我应该将文件保存在Bootstrap还是wamp中 <?php if ($_POST['submit']) {
<?php
if ($_POST['submit']) {
if(!$_POST['name']) {
$error="<br/>-Please enter your name";
}
if(!$_POST['email']) {
$error.="<br/>- Please enter your email";
}
if(!$_POST['subject']) {
$error.="<br/>- Please enter a subject";
}
if(!$_POST['message']) {
$error.="<br/>- Please enter a message";
}
if(!$_POST['check']) {
$error.="<br/>- Please confirm you are human";
}
if($error) {
$result="Whoops, there is an error; Please correct the following: $error";
} else {
mail("namitajamwal19@gmail.com", "Contact message", "Name: ".$_POST['name']."
Email: ".$_POST['name']."
Subject: ".$_POST['subject']."
Message: ".$_POST['message']);"
{
$result="Thank you, I'll be in touch shortly";
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Contact Us</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<section id="contact">
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h1>Contact Us</h1>
<?php echo $result;?>
<p>Send a message via the form below</p>
<form method="post" role="form">
<div class="form-group">
<input type="text" name="name" class="form-control" placeholder="Your Name" value="<?php echo $_POST['name']; ?>">
</div>
<div class="form-group">
<input type="email" name="email" class="form-control" placeholder="Your email" value="<?php echo $_POST['email']; ?>">
</div>
<div class="form-group">
<textarea name="subject" rows="5" class="form-control" placeholder="Subject"><?php echo $_POST['subject']; ?></textarea>
</div>
<div class="form-group">
<textarea name="message" rows="5" class="form-control" placeholder="Message..."><?php echo $_POST['message']; ?></textarea>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="check">I am Human
</label>
</div>
<div align="center">
<input type="submit" name="submit" class="btn btn-secondary" value="send message"/>
</div>
</form>
</div>
</div>
</div>
</section>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>
通过下面的表单发送消息
我是人
为了处理php,该文件需要有一个.php扩展名,您可以将其存储在webroot中,webroot就是保存.html文件的地方
如果您的php没有运行,则可能是php错误,或者您的Web服务器没有正确配置以处理php文件
You need to change your extension `.html` to `.php`
如果仍然希望将php文件作为.html
提供,请在中创建一个.htaccess文件
在您的目录和
`AddType application/x-httpd-php .html .htm`
它将开始工作您必须使用“.php”扩展名(如“test.php”)保存文件,并将其保存在wamp服务器文件夹:“c:\wamp\www”中。
在浏览器中运行php文件:localhost/test.php。
希望这对你有帮助,兄弟。我想你只是没有抓住要点: 在阅读了你的问题之后,我认为你只是将项目文件直接放入wamp的
www
目录中。所以说,我没有去工作。另外,您提到在index.html
中,您的PHP
代码不工作也是一个明显的错误,即要运行PHP
代码,您需要为该文件提供一个.PHP
扩展名
为了在wamp服务器中运行PHP文件,我应该将文件保存在哪里
在引导中还是在Wamp中
<?php
if ($_POST['submit']) {
if(!$_POST['name']) {
$error="<br/>-Please enter your name";
}
if(!$_POST['email']) {
$error.="<br/>- Please enter your email";
}
if(!$_POST['subject']) {
$error.="<br/>- Please enter a subject";
}
if(!$_POST['message']) {
$error.="<br/>- Please enter a message";
}
if(!$_POST['check']) {
$error.="<br/>- Please confirm you are human";
}
if($error) {
$result="Whoops, there is an error; Please correct the following: $error";
} else {
mail("namitajamwal19@gmail.com", "Contact message", "Name: ".$_POST['name']."
Email: ".$_POST['name']."
Subject: ".$_POST['subject']."
Message: ".$_POST['message']);"
{
$result="Thank you, I'll be in touch shortly";
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Contact Us</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<section id="contact">
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h1>Contact Us</h1>
<?php echo $result;?>
<p>Send a message via the form below</p>
<form method="post" role="form">
<div class="form-group">
<input type="text" name="name" class="form-control" placeholder="Your Name" value="<?php echo $_POST['name']; ?>">
</div>
<div class="form-group">
<input type="email" name="email" class="form-control" placeholder="Your email" value="<?php echo $_POST['email']; ?>">
</div>
<div class="form-group">
<textarea name="subject" rows="5" class="form-control" placeholder="Subject"><?php echo $_POST['subject']; ?></textarea>
</div>
<div class="form-group">
<textarea name="message" rows="5" class="form-control" placeholder="Message..."><?php echo $_POST['message']; ?></textarea>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="check">I am Human
</label>
</div>
<div align="center">
<input type="submit" name="submit" class="btn btn-secondary" value="send message"/>
</div>
</form>
</div>
</div>
</div>
</section>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>
要使用WAMP
运行PHP文件,您需要遵循以下基本步骤:
Wamp
的所有相关详细信息,您可以下载它并安装在本地驱动器上WWW
这是您可以放置项目的地方test\u项目
WAMP/WWW/test\u项目
bootstrap
模板和index.php
。阅读完您的问题后,我认为您只是将项目模板文件放入www
目录中,因此请更改该目录index.php
,您可以转到浏览器并键入localhost/test\u project
。这将自动运行项目的index.php
文件请提一下这个错误当有人说“代码似乎不起作用”时,我真的很生气。。。至少应该有一些解释,比如“根本没有输出”,“我收到了一条胡说八道的错误消息”,“应用程序崩溃”。。。等等,汉克斯!这真的帮了我的忙。@NamitaJamwal你能接受这个答案吗。如果有帮助的话。谢谢,谢谢@NamitaJamwal继续编码。