简体   繁体   English

使用 wamp 服务器时,php 代码未在 Dreamweaver 中运行

[英]php code is not running in dreamweaver while using wamp server

im working on a web site it has html and php when i run the php script in dreamweaver it is executing html code but not php.it is not accessing other html pages given in the following code我在一个有 html 和 php 的网站上工作,当我在 Dreamweaver 中运行 php 脚本时,它正在执行 html 代码但不是 php。它没有访问以下代码中给出的其他 html 页面

  </p>
<form method="post" action="" >
 <p>Enter your source and destination.</p>
<p>
    From:</p>
<select name="from">
<option value="Islamabad">Islamabad</option>
<option value="Lahore">Lahore</option>
<option value="murree">Murree</option>
<option value="Muzaffarabad">Muzaffarabad</option>
</select>
<p>
    To:</p>
   <select name="To">
<option value="Islamabad">Islamabad</option>
<option value="Lahore">Lahore</option>
<option value="murree">Murree</option>
<option value="Muzaffarabad">Muzaffarabad</option>
</select>
<input type="submit" value="search" /> 
</form>
</form> </table>
<?php
if(isset($_POST['from']) and isset($_POST['To'])) {
$from = $_POST['from'] ;
$to = $_POST['To'] ;
$table = array($from, $to);

switch ($table) {
  case array ("Islamabad", "Lahore") :
  header("Location: flights.html");
 break;
  case array ("Islamabad", "Murree") :
  header("Location: hotels.html");
 break;
  case array ("Islamabad", "Muzaffarabad") :
 header("Location: videos.html");
 break;
//.....
//......
default:
echo "Your choice is nor valid !!";
}

}
?>

So many problems!这么多问题!

From the PHP online Manual来自 PHP 在线手册

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.请记住,必须在发送任何实际输出之前调用 header(),无论是通过普通的 HTML 标记、文件中的空行还是来自 PHP。 It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called.使用 include 或 require 函数或其他文件访问函数读取代码,并且在调用 header() 之前输出空格或空行,这是一个非常常见的错误。 The same problem exists when using a single PHP/HTML file.使用单个 PHP/HTML 文件时存在同样的问题。

So basically if you want to make the browser load a new page using header() you have to execute the header() before any other data ( HTML ) is sent to the browser.所以基本上如果你想让浏览器使用header()加载一个新页面,你必须在任何其他数据 (HTML) 发送到浏览器之前执行header() It is also a good idea to follow any header() with an exit;在任何header()后面跟着一个exit;也是一个好主意exit; . .

This might not be too difficult in your case as it looks to me like this code should go at the top of the script and not here in the middle of it anyway.在您的情况下,这可能不太困难,因为在我看来,这段代码应该放在脚本的顶部,而不是放在脚本的中间。

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

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