javascript – running number begins from 1 every year-ThrowExceptions

Exception or error:

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?

How to solve:

I am not having experience in php as i am a java developer but I can help you with script

In Java script you need to
Convert the date to Date format by using

var date=new  Date(document.getElementById('sdate').value) var year=date.getFullYear(); var month =date.getMonth()+1; var dateOnly=date.getDate();

Hope it clarified your doubt

Leave a Reply

Your email address will not be published. Required fields are marked *