使用 tomcat 6.0 运行 php 脚本时为什么代码显示在浏览器上

发布于 2024-12-20 07:12:20 字数 1303 浏览 4 评论 0原文

我正在尝试使用 apache tomcat6.0 运行 php 脚本。我使用 netbeans 作为我的编辑器。运行时没有错误,并收到消息构建成功。我有两个程序welcome.php 和form.jsp。 form.jsp 用于用户输入表单及其在浏览器上的显示。但是当我提交表单时,welcome.php 不起作用,它在浏览器上给了我程序代码。这是我的welcome.php。

    $query1="select * from company";
    $result1 = odbc_exec($connect, $query1);

   #fetch the data from the database
    while(odbc_fetch_row($result1)){
     $cnamearray[$count] = odbc_result($result1, 1);
   $enamearray[$count] = odbc_result($result1, 2);

   if($cnamearray[$count]==$_POST['cname'])
  {
     print "<script> alert(\"cname Exists\"); </script>";
    exit();
   }

 if($enamearray[$count]==$_POST['ename'])
   {
 print "<script> alert(\"eName Exists\"); </script>";
 exit();
   }
   }
   $query=("INSERT INTO company(cname,ename) VALUES ('$_POST[cname]','$_POST[ename]') ");
 $result = odbc_exec($connect, $query);
echo "<script> alert(\"Row Inserted\"); </script>";

 ?>

 "; exit(); } if($enamearray[$count]==$_POST['ename']) { print ""; exit(); } }
 $query=("INSERT     INTO company(cname,ename) VALUES ('$_POST[cname]','$_POST
  [ename]') ");        
 $result = odbc_exec($connect, $query); echo ""; ?> 

在浏览器上获取这些代码。

为什么代码显示在浏览器上。我必须做什么才能获得输出。我怎样才能在tomcat中运行php脚本

i am trying to run php script using apache tomcat6.0. am using netbeans as my editor. there is no errors while running and got a message build succesfull. i have two programs welcome.php and form.jsp. the form.jsp is used for user entry form and its displaying on the browser. but when i submit the form the welcome.php is not working and its giving me program code on browser. this is my welcome.php.

    $query1="select * from company";
    $result1 = odbc_exec($connect, $query1);

   #fetch the data from the database
    while(odbc_fetch_row($result1)){
     $cnamearray[$count] = odbc_result($result1, 1);
   $enamearray[$count] = odbc_result($result1, 2);

   if($cnamearray[$count]==$_POST['cname'])
  {
     print "<script> alert(\"cname Exists\"); </script>";
    exit();
   }

 if($enamearray[$count]==$_POST['ename'])
   {
 print "<script> alert(\"eName Exists\"); </script>";
 exit();
   }
   }
   $query=("INSERT INTO company(cname,ename) VALUES ('$_POST[cname]','$_POST[ename]') ");
 $result = odbc_exec($connect, $query);
echo "<script> alert(\"Row Inserted\"); </script>";

 ?>

am getting

 "; exit(); } if($enamearray[$count]==$_POST['ename']) { print ""; exit(); } }
 $query=("INSERT     INTO company(cname,ename) VALUES ('$_POST[cname]','$_POST
  [ename]') ");        
 $result = odbc_exec($connect, $query); echo ""; ?> 

these codes on browser.

why the codes are displaying on the browser . what i must do to get output. how can i run php script in tomcat

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

杀お生予夺 2024-12-27 07:12:20

Tomcat 本身是一个 Java servlet/JSP 容器,对 PHP 一无所知——您意识到了,对吗?您需要进行某种不正当的修改才能使 PHP 在 Tomcat 上运行。 这里是 Google 搜索的“Tomcat PHP”,看起来它确实描述了这样的内容一个黑客。

愿克苏鲁怜悯你的灵魂。

Tomcat by itself is a Java servlet/JSP container, and knows nothing about PHP -- you realize that, right? You need to do some sort of unholy hack to get PHP working on Tomcat. Here is a Google hit for "Tomcat PHP", and it looks like it does indeed describe just such a hack.

May Cthulhu have mercy on your soul.

梦旅人picnic 2024-12-27 07:12:20

看起来您需要在 $query1 行中添加右引号和分号

$query1="select * from company

应该是...

 $query1="select * from company";

It looks like you need to add a closing quotation mark and semi-colon to your $query1 line

$query1="select * from company

Should be...

 $query1="select * from company";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文