简体   繁体   中英

Automatize receipt number

I'm trying to make a receipt printing website. I want to be able to increment the receipt number each type a new receipt gets printed, for example, first time ever printing, the number will be 1, second time 2, etc. The numbers should not repeat automatically, because doing this manually wouldn't be good since we tend to forget the last number we were on. I have been looking on the Internet for solutions but I have not found any. Please may I have some help? here is what my receipt looks like: 在此处输入图像描述 in the place that says "recu n 2839" I want there to be an automatically generated number by order. here is my form code:

<!DOCTYPE html>
<html>

<head>

    <title>Reçu</title>

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
    <link rel="stylesheet" href="PdfStyles.css">
    <link rel="icon" type="image/x-icon" href="img/schoolicon.png">

</head>

<body>
    <style>
        body {
            background-image: url('img/backo.jpg');
        }
    </style>
    <br>
    <br>


    <div class="hero">
        <div class="mt-5">



            <form action="pdfmaker.php" method="post" class=" offset-md-3 col-md-6" style="text-align:center;">

                <h1 style="color:white">Création de reçu</h1>

                <div class="row mb-2  ">
                    <div class="col-md-6 mb-2"><input type="text" name="nrecu" placeholder="Numéro Reçu" class="form-control" required></div>
                    <div class="col-md-6"><input type="text" name="fname" placeholder="Élève" class="form-control" required></div>
                    <div class="col-md-6 mb-2"><input type="text" name="nClass" placeholder="Classe" class="form-control" required></div>

                    <div class="col-md-6 mb-2"><input type="text" name="Moi" placeholder="Mois" class="form-control" required></div>
                    <div class="col-md-6 mb-2"><input type="text" name="Mont" placeholder="Montant" class="form-control"></div>
                    <div class="col-md-6"><input type="text" name="anne" placeholder="Année scolaire" class="form-control" required></div>
                    <div class="col-md-6 mb-2"><input type="text" name="total" placeholder="Total" class="form-control" required></div>
                    <div class="col-md-6 mb-2"><form action="/pdfmaker.php">
                        <label  style="font-family:fantasy;font-size:15px"for="cars">Mode de paimenet:</label>
                        <select name="mode" id="mod">
                            <option value="Espèce - نقدا">Espèce - نقدا</option>
                            <option value="Chèque - صك بنكي">Chèque - صك بنكي </option>
                            <option value="Carte Bancaire - بطاقة بنكية">Carte Bancaire - بطاقة بنكية</option>
                        </select>
                        <br><br>
                    </form></div>


                    <button style="background-color: #8064A2 !important; font-family:fantasy;font-size:30px" type="submit" class="btn btn-success btn-lg btn-block">Imprimer</button>







            </form>

        </div>

    </div>




</body>

</html>

the " nrecu " div is the one that takes care of the number, this line:

<div class="col-md-6 mb-2"><input type="text" name="nrecu" placeholder="Numéro Reçu" class="form-control" required></div>

and I believe I'd be able to achieve what I wanted just from this code, but if not, i'll include the pdf maker code, that generates the pdf.

this is the part of the pdf generation code that handles that number: first:

$nrecu=$_POST['nrecu'];

second:

<p style="text-align:center;font-family:monospace;">Reçu N° '.$nrecu.' ايصال رقم </p>

any help will be apperciated.

you could try to do that PHP create a file if not exists and on every print update the value in it. This should look like:

    $file = fopen("my_file.txt", "a"); // try to open the file, if not exist create it

    if(filesize("my_file.txt") == 0){ // if the file is empty, write it with the value 1
        fwrite($file, "1");
    }else{ // if the file is correct execute the code
        $value = file_get_contents("my_file.txt", "r"); // get the value of the first line
        ftruncate($file, 0); // remove the first line
        fwrite($file, $value + 1); // write the new value on the first line
        $nrecue = file_get_contents("my_file.txt", "r");
}

and now you just need to set the value in you html

Hope this helped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM