使用 Bootstrap 时 PHP 文件不起作用 [英] PHP files not working when using Bootstrap

查看:26
本文介绍了使用 Bootstrap 时 PHP 文件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程新手,因此需要一些帮助.下面是我使用 Bootstrap 用于联系表单的代码,但我的 PHP 代码似乎不起作用.我一直将index.php"文件与 Bootstrap 的其他文件一起保存.但是当我运行它时,它显示一个错误并且没有运行.当我将此文件保存为index.html"时,代码的 HTML 部分会运行,但 PHP 文件不会.为了在 wamp 服务器中运行 PHP 文件,我应该将文件保存在 Bootstrap 中还是 Wamp 中?

<!DOCTYPE html><html lang="zh-cn"><头><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><!-- 以上 3 个元标记 * 必须* 排在首位;任何其他头部内容必须在*这些标签之后* --><title>联系我们</title><!-- 引导程序--><link href="css/bootstrap.min.css" rel="样式表"><!-- 用于 HTML5 元素和媒体查询的 IE8 支持的 HTML5 shim 和 Respond.js --><!-- 警告:如果您通过 file://查看页面,Respond.js 将不起作用 --><!--[如果是 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]--><身体><section id="联系人"><div class="容器"><div class="row"><div class="col-md-6 col-md-offset-3"><h1>联系我们</h1><?php echo $result;?><p>通过下面的表格发送消息</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 class="form-group"><input type="email" name="email" class="form-control" placeholder="Your email" value="<?php echo $_POST['email']; ?>">

<div class="form-group"><textarea name="subject" rows="5" class="form-control" placeholder="Subject"><?php echo $_POST['subject'];?></textarea>

<div class="form-group"><textarea name="message" rows="5" class="form-control" placeholder="Message..."><?php echo $_POST['message'];?></textarea>

<div class="checkbox"><标签><input type="checkbox" name="check">我是人类

<div align="center"><input type="submit" name="submit" class="btn btn-secondary" value="发送消息"/>

</表单>

</节><!-- jQuery(Bootstrap 的 JavaScript 插件所必需的)--><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script><!-- 包含所有已编译的插件(如下),或根据需要包含单个文件 --><script src="js/bootstrap.min.js"></script></html>

解决方案

我认为你只是没抓住重点:

阅读你的问题后,我认为你只是将项目文件直接放入wamp的www目录中.如此肥胖以至于没有工作.此外,您提到在 index.html 中,您的 PHP 代码不起作用也是运行 PHP 代码需要提供的明显错误该文件为 .php 扩展名.

<块引用>

为了在 wamp 服务器中运行 PHP 文件,我应该在哪里保存文件在 Bootstrap 中还是在 Wamp 中?

要使用 WAMP 运行 PHP 文件,您需要遵循以下基本步骤:

<小时>

  1. 安装 Wamp:这是有关 WAMP 的所有相关详细信息,您可以下载它并安装到您的本地驱动器上.wampserver

  2. 安装后进入 WAMP 目录并找到 WWW 这是您可以放置​​项目的地方.

  3. 现在只需创建您的项目文件夹.即 test_projectWAMP/WWW/test_project

  4. 现在在这个项目文件夹中,你可以添加你的项目 bootstrap 模板和你的 index.php.阅读您的问题后,我认为您只是将项目模板文件放入 www 目录中,因此请更改它.

  5. 现在打开这个index.php,你可以在浏览器中输入localhost/test_project.这将自动运行您的项目的 index.php 文件.

I am new to Programming hence need some help. Below is the code I am using for a Contact Form using Bootstrap but my PHP code doesn't seem to work. I have been keeping "index.php" file with other files of Bootstrap. But when I run this it shows an error and doesn't run. And when I save this file as "index.html", the HTML part of the code runs but PHP files don't. In order to run PHP file in wamp server where should I save the files in Bootstrap or in 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>

解决方案

I think You simply missing the point:

After reading your question I think you just put the project files directly into the www directory of wamp. so obesely that not gone work. Also, you mention that in index.html your PHP code is not working is also obvious error that to run a PHP code you need to give that file a .php extension.

In order to run PHP file in wamp server where should I save the files in Bootstrap or in Wamp?

To run a PHP file with WAMP you need to follow this basic step:


  1. Install Wamp: Here is the all related detail about WAMP and you could download it and install on your local drive. wampserver

  2. After installing it go to the WAMP directory and find WWW this is the place where you can put your projects in.

  3. Now Simply Create your project folder. i.e test_project WAMP/WWW/test_project

  4. Now inside this project folder, you can add your project bootstrap template and your index.php. After reading your question I think you just put the project template files into www directory so please change that.

  5. Now to open this index.php you can go to your browser and type localhost/test_project. This will automatically run an index.php file of your project.

这篇关于使用 Bootstrap 时 PHP 文件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆