I am trying to create a from which takes input from the user and stores its a database called patientappointment_db. I created the following form in html:
<form id="form1" name="form1" method="post" action="doctor.php">
<label for="EmployeeID">EmployeeID</label><input type="text" name="EmployeeID" id="EmployeeID" />
<br class="clear" />
<label for="Name">Name</label><input type="text" name="Name" id="Name" />
<br class="clear" />
<label for="Specialty">Specialty</label><input type="text" name="Specialty" id="Specialty" />
<br class="clear" />
<label for="Department">Department</label><input type="text" name="Department" id="Department" />
<br class="clear" />
<label for="HospitalID">HospitalID</label><input type="text" name="HospitalID" id="HospitalID" />
<br class="clear" />
<label for="LicenseNo">LicenseNo</label><input type="text" name="LicenseNo" id="LicenseNo" />
<br class="clear" />
<input type="submit" name="suibmit" id="suibmit" value="suibmit" />
<br class="clear" />
</form>
My connect file:
<?php
$servername = "localhost";
$database = "patientappointment_db";
$username = "root";
$password = "";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
mysqli_close($conn);
?>
Finally my PHP query
<?php include 'connect.php';?>
<?php //Post Params
$EmployeeID = $_POST['EmployeeID'];
$Name = $_POST['Name'];
$Specialty = $_POST['Specialty'];
$Department = $_POST['Department'];
$HospitalID = $_POST['HospitalID'];
$LicenseNo = $_POST['LicenseNo'];
?>
<?php //Query
//INSERT
$query = " INSERT INTO doctor ( EmployeeID, Name, Specialty, Department, HospitalID, LicenseNo ) VALUES ( '$EmployeeID', '$Name', '$Specialty', '$Department', '$HospitalID', '$LicenseNo' ) ";
$result = mysql_query($query);
if( $result )
{
echo 'Success';
}
else
{
echo 'Query Failed';
}
?>
When I am hitting the submit button my output is the the below html code and not the success message and no value is being entered in the database.
<?php include 'connect.php';?>
<?php //Post Params
$EmployeeID = $_POST['EmployeeID'];
$Name = $_POST['Name'];
$Specialty = $_POST['Specialty'];
$Department = $_POST['Department'];
$HospitalID = $_POST['HospitalID'];
$LicenseNo = $_POST['LicenseNo'];
?>
<?php //Query
//INSERT
$query = " INSERT INTO doctor ( EmployeeID, Name, Specialty, Department, HospitalID, LicenseNo ) VALUES ( '$EmployeeID', '$Name', '$Specialty', '$Department', '$HospitalID', '$LicenseNo' ) ";
$result = mysql_query($query);
if( $result )
{
echo 'Success';
}
else
{
echo 'Query Failed';
}
?>
I am not sure where my problem is and what to do to solve this error.