使用 tomcat 6.0 运行 php 脚本时为什么代码显示在浏览器上
我正在尝试使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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.
看起来您需要在 $query1 行中添加右引号和分号
应该是...
It looks like you need to add a closing quotation mark and semi-colon to your $query1 line
Should be...