我是編程新手,因此需要一些幫助。以下是我用於使用Bootstrap的聯繫表單的代碼,但我的PHP代碼似乎不起作用。 我一直在使用Bootstrap的其他文件保存「index.php」文件。但是當我運行它時,它顯示一個錯誤並且不運行。 當我將這個文件保存爲「index.html」時,代碼的HTML部分會運行,但PHP文件不會。 爲了在wamp服務器中運行PHP文件,我應該在Bootstrap還是Wamp中保存這些文件?PHP文件在使用Bootstrap時不起作用
<?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("[email protected]", "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>
PLZ提到錯誤 –
這真的會激怒我,當有人說「代碼似乎並不工作」 ......至少應該有一些解釋,如「有沒有輸出」,「我得到等等等等錯誤信息「,」應用程序崩潰「...等 – Khan