I'd wish to make a number that will start from 1 in the beginning of a brand new year, is it possible to do so?
When the user enters the date
It will save into two types (One is full date in the date column
, the other is to take the year of the date and insert it into the year
column of the sf_table
Table)
HTML:
//Date
<div>
<label for="SDate">Insert Date</label></br>
<input type="date" id="sdate" name="SDate" value="<?php echo date('Y-m-d') ?>" required>
</div>
//Auto output the display of the running number (That will save into the database once the submit button is pressed)
<div>
<label for="Rno">Running Number</label></br>
<input type="text" name="Rno" id="runningno" readonly>
</div>
PHP: (When the submit button is pressed)
if(isset($_POST['submit'])){
$year = //(get year from $date);
$date = mysqli_real_escape_string($db, $_POST['SDate']);
$rnum = mysqli_real_escape_string($db, $_POST['Rno']);
$stmt = $dbh->prepare("insert into sf_table (date,year,rnum) values (?,?,?)");
$stmt -> bindParam(1,$date);
$stmt -> bindParam(2,$year);
$stmt -> bindParam(3,$rnum);
$stmt -> execute();
}
What Javascript functions and sql statements I should write and modify in my .php file to conduct this?