I'm developing irctc similar website similar project as college assignment. I'm providing user to search any train running on given date and validating from database. I'm using php and mysql and getting no error as well as invalid response from code. Please look at the code:
if (isset($_POST['btn_no'])) {
$current_date=date("Y-m-d");
$selected_date=$_POST['date'];
$no=$_POST['train_no'];
if ($selected_date>=$current_date) {
$query="SELECT train_no FROM `trains` WHERE train_no='$no'";
$found=$db->query($query);
$rows=$found->num_rows;
if ($rows==1) {
$_SESSION['train_id']=$no;
$_SESSION['date']=$_POST['date'];
header("Location: showtrain.php");
}
elseif ($rows==0) {
?>
<script>alert("Train no. invalid !")</script>
<?php
}
}
elseif ($selected_date<$current_date) {
?>
<script>alert("Wrong date");</script>
<?php
}
}
Every time <script>
is executed.