I am a student and I a am making a system for our project. I want to Add information but when I input data in my form, no data has been added. I tried checking my database and there's no data added. Please help.
I tried checking my database and everything are all good. EVerything are matched in my codes but I still cant add information in my database
Here are my codes:
`<?php
session_start();
if(!isset($_SESSION['UserLogin'])){
header("Location: login.php");
exit;
}
include_once('connections.php');
$con = connection();
if (isset($_POST['first_name']) && isset($_POST['last_name']) && isset($_POST['date_of_birth']) && isset($_POST['gender']) && isset($_POST['address']) && isset($_POST['category']) && isset($_POST['state']) && isset($_POST['medical_history']) && isset($_POST['date_of_admission']) && isset($_POST['diagnoses']) && isset($_POST['prescription']) && isset($_POST['phone_number'])) {
$first_name = mysqli_real_escape_string($con, $_POST['first_name']);
$last_name = mysqli_real_escape_string($con, $_POST['last_name']);
$date_of_birth = mysqli_real_escape_string($con, $_POST['date_of_birth']);
$gender = mysqli_real_escape_string($con, $_POST['gender']);
$address = mysqli_real_escape_string($con, $_POST['address']);
$category = mysqli_real_escape_string($con, $_POST['category']);
$state = mysqli_real_escape_string($con, $_POST['state']);
$medical_history = mysqli_real_escape_string($con, $_POST['medical_history']);
$date_of_admission = mysqli_real_escape_string($con, $_POST['date_of_admission']);
$diagnoses = mysqli_real_escape_string($con, $_POST['diagnoses']);
$prescription = mysqli_real_escape_string($con, $_POST['prescription']);
$phone_number = mysqli_real_escape_string($con, $_POST['phone_number']);
$sql = "INSERT INTO patient_rec (First_name, Last_name, Date_of_birth, Gender, Address, Category, State, Medical_history, Date_of_admission, Diagnoses, Prescription, Phone_number) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$stmt = $con->prepare($sql);
$stmt->bind_param("sssssssssss", $first_name, $last_name, $date_of_birth, $gender, $address, $category, $state, $medical_history, $date_of_admission, $diagnoses, $prescription, $phone_number);
$stmt->execute();
}
mysqli_close($con);
session_write_close();
header("Location: index.php");
exit;
?>
<?php
session_start();
if (!isset($_SESSION['UserLogin']) || !$_SESSION['UserLogin']) {
header('Location: login.php');
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content ="width=device-width, initial-scale=.75">
<link rel="stylesheet" type="text/css" href="addform.css">
<body>
</br>
<h1>Add Patient Information</h1>
<h2>Bayawan District hospital</h2>
<h3>236 Zamora St, Bayawan City, 6221 Negros Oriental</h3>
</br>
<img src="logo.png" alt="Logo" class="logo">
<form action="add.php" method="POST">
<label for="first_name">First Name:</label><br>
<input type="text" name="first_name" id="first_name" placeholder="Please type your first name" required><br>
<label for="last_name">Last Name:</label><br>
<input type="text" name="last_name" id="last_name" placeholder="Please type your last name" required><br>
<label for="date_of_birth">Date of Birth:</label><br>
<input type="date" name="date_of_birth" id="date_of_birth" required><br>
<label for="gender">Gender:</label><br>
<input type="radio" name="gender" value="male" id="gender_male"> Male
<input type="radio" name="gender" value="female" id="gender_female"> Female<br>
<label for="address">Address:</label><br>
<input type="text" name="address" id="address" placeholder="Please type your address" required><br>
<label for="phone_number">Phone Number:</label><br>
<input type="text" name="phone_number" id="phone_number" pattern="[0-9]{11}" required>
<label for="category">Category:</label><br>
<select name="category" id="category" required>
<option value="">-Select Choices-</option>
<option value="Primary Care">Primary Care</option>
<option value="Specialty Care">Specialty Care</option>
<option value="Emergency Care">Emergency Care</option>
<option value="Urgent Care">Urgent Care</option>
<option value="Long-term Care">Long-term Care</option>
<option value="Hospice Care">Hospice Care</option>
<option value="Mental Healthcare">Mental Healthcare</option>
</select><br>
<label for="state">Status:</label><br>
<select name="state" id="state" required><br>
<option value="">-Select Choices-</option>
<option value="New patient">New patient</option>
<option value="Established patient">Established patient</option>
<option value="Outpatient">Outpatient</option>
<option value="Inpatient">Inpatient</option>
</select><br>
<label for="medical_history">Medical History:</label><br>
<textarea name="medical_history" id="medical_history" placeholder="Please type here..." rows="4" cols="50" required></textarea><br>
<label for="date_of_admission">Date of Admission:</label><br>
<input type="date" name="date_of_admission" id="date_of_admission" required><br>
<label for="diagnoses">Diagnoses:</label><br>
<textarea name="diagnoses" id="diagnoses" placeholder="Please type here..." rows="4" cols="50" required></textarea><br>
<label for="prescription">Prescription:</label><br>
<textarea name="prescription" id="prescription" placeholder="Please type here..." rows="4" cols="50" required></textarea><br>
<input type="submit" value="Add Patient">
<a href="index.php"><button type="button" class="logbtn">Cancel</button></a>
</form>
</body>
`