0

I've created a php script for my registration page to insert new registration details into a MySQL Workbench database, however when I attempt to execute this script by using a submit button on the registration jsp page, the whole php code appears so evidently it has not been executed.

I am using the IntelliJ Ultimate edition which has the PHP plugin. This is a webapp which I deploy using tomcat

I also attempted to put and tags before and after the PHP code to see if it was just an error in terms of displaying output but this didn't solve the issue.

These are the relevant parts of the registration jsp page which collect user input and then post them :

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

Here is the php script which I am trying to execute:

<?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();
}
?>

This is the result: enter image description here

sh.learner
  • 63
  • 2
  • 10

1 Answers1

0

Your issue here is that Apache Tomcat is a Java Application container, and does not execute PHP code.

Is running this script through PHP and not inserting the data via JSP or a servlet not an option?

If you must run PHP for some reason, maybe This Question will help you out

Zachary Craig
  • 2,192
  • 4
  • 23
  • 34
  • I followed steps 1-14 from the answer in that question however I still have the same issue so I'm not sure if other configuration is required – sh.learner Feb 01 '19 at 20:31