【问题标题】:How to execute php script for web application in IntelliJ?如何在 IntelliJ 中为 Web 应用程序执行 php 脚本?
【发布时间】:2019-06-25 03:03:43
【问题描述】:

我已经为我的注册页面创建了一个 php 脚本,以便将新的注册详细信息插入 MySQL Workbench 数据库,但是当我尝试使用注册 jsp 页面上的提交按钮来执行此脚本时,整个 php 代码出现了显然它没有被执行。

我正在使用带有 PHP 插件的 IntelliJ Ultimate 版本。这是我使用 tomcat 部署的 webapp

我还尝试在 PHP 代码之前和之后放置和标记,以查看它是否只是显示输出方面的错误,但这并没有解决问题。

这些是注册 jsp 页面的相关部分,它们收集用户输入然后发布它们:

<form action="registered.php" method="POST">
 .............
 <input type="submit" value="Submit"/>
</form>

这是我正在尝试执行的 php 脚本:

<?php
$host_name = $_POST[host_name];
$host_password = $_POST[host_password];
$f_name = $_POST[f_name];
$s_name = $_POST[s_name];
$gender = $_POST[gender];
$house_num = $_POST[house_num];
$road = $_POST[road];
$city = $_POST[city];
$postcode = $_POST[postcode];
$country = $_POST[country];
$mobile = $_POST[mobile];
$dob = $_POST[dob];

if (!empty($host_name) || !empty($host_password) ||!empty($f_name) ||!empty($s_name) || !empty($gender) || !empty($house_num) || !empty($road) || !empty($city) || !empty($postcode) || !empty($country) || !empty($mobile) || !empty($dob)) {

$host = "jdbc:mysql://localhost/project";
$username = "projectuser";
$password = "test123";

$conn = new mysqli($host, $username, $password);
if (mysqli_connect_error()) {
    die('Connect Error(' . mysqli_connect_errno() . ')' . mysqli_connect_error());
} else {
    $SELECT = "SELECT host_name FROM hosts WHERE host_name = ? Limit 1";
    $INSERT = "INSERT INTO hosts (host_name, host_password, f_name, s_name, gender, house_num, road, city, postcode, country, mobile, dob) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    $stmt = $conn->prepare($SELECT);
    $stmt->bind_param("s", $host_name);
    $stmt->execute();
    $stmt->bind_result($host_name);
    $stmt->store_result();
    $rnum = $stmt->num_rows;
    if ($rnum == 0) {
        $stmt->close();
        $stmt = $conn->prepare($INSERT);
        $stmt->bind_param("sssssissssss", $host_namename, $host_password, $f_name, $s_name, $gender, $house_num, $road, $city, $postcode, $country, $mobile, $dob);
        $stmt->execute();
        echo "You have registered successfully";
    } else {
        echo "Someone already registered with this username";
    }
    $stmt->close();
    $conn->close();
}
}else{
    echo "All field are required";
    die();
}
?>

这是结果:

【问题讨论】:

    标签: php sql tomcat mysqli mysql-workbench


    【解决方案1】:

    您的问题是 Apache Tomcat 是一个 Java 应用程序容器,不执行 PHP 代码。

    是否通过 PHP 运行此脚本,而不是通过 JSP 或 servlet 插入数据不是一个选项?

    如果您出于某种原因必须运行 PHP,也许This Question 会帮助您

    【讨论】:

    • 我按照该问题的答案中的步骤 1-14 进行操作,但我仍然遇到同样的问题,所以我不确定是否需要其他配置
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-22
    • 1970-01-01
    • 2018-03-28
    • 2017-11-18
    • 2015-08-17
    相关资源
    最近更新 更多