Home > OS >  I want to update my results from table and post them to the browser, but it isnt working
I want to update my results from table and post them to the browser, but it isnt working

Time:01-05

I want an increment result for my invoice id from the table

Simply If my code is already in DB like E-0000007, I want to fetch it and add 1 to E-0000008

most probably I have written if statement two times incorrectly,

I searched everywhere, (maybe not much because I don't know what I should search), If you understand what I want to implement please consider helping me

My code .php

    <?php
      if(isset($_POST['post']))
      {
        $invoiceid = mysqli_real_escape_string($con,$_POST['invoiceid']);
    
        $sql="INSERT INTO `student`(`invoiceid`) VALUES ('$invoiceid')";
    
        $result=mysqli_query($con,$sql);
    
        $row = mysqli_fetch_array($result);

        $lastid = $row['invoiceid'];

    if(empty($lastid))
      {
        $number = "E-0000001";
      }
        else
      {
        $idd = str_replace("E-", "", $lastid);
        $id = str_pad($idd   1, 7, 0, STR_PAD_LEFT);
         $number = 'E-'.$id;
      }
      
      
    
    if($result)
    {
    $success="Post has been added successfully";
    } else 
    {
        $error="Something went wrong!"; 
    }
    
    $invoiceid = '';
     }
    
    ?>

CodePudding user response:

try code

if(empty($lastid)) { 
  $number = "E-0000001"; 
} else { 
  $lastid = "0000001"   1; 
  $numbers = sprintf('d', $lastid ); 
  echo 'E-'.$numbers; 
}
  • Related