0

I have created a code to generate order id using auto increment and then the code is called in separte file. the code is properly working on local server but once i uploaded on online server all the auto incremantal code is workking proper but order id is not updating.kindly guide me here is my code

**

create_order.php
<?php
include('company_connection.php');
include ('connection.php');
session_start();
$query_orderid="INSERT INTO `create_order` (`order_id`) VALUES ('')";
 $data_orderid=mysqli_query($connect,$query_orderid);
$query_getorderid="select * from  create_order";
$data_getorderid=mysqli_query($connect,$query_getorderid);
    $total_data_getorderid=mysqli_num_rows($data_getorderid);
     if( $total_data_getorderid!=0)
                    {
                                               while($result_getorderid=mysqli_fetch_assoc($data_getorderid) )  
                        {
                            $lastest_getorderid = $result_getorderid['order_id'];
                          //  echo "Last order id is".$lastest_getorderid;
                            $_SESSION["order_id"]=$lastest_getorderid;

                         }  
                    }
                    else
                        {
                            echo "esle running of orderid";
                        }

?>
client_info.php
<?php
include ('connection.php');
include ('order_create.php');
session_start();
echo "order number is ".$_SESSION["order_id"];
 echo "user id ".$_SESSION["user_id"];
?>

**

  • 1
    If `order_id` is the auto increment key, then you should be inserting NULL (I think `DEFAULT` also works) and not `''`. – Nigel Ren Jun 13 '20 at 13:17
  • You get the generated id by using the [`mysqli_insert_id()`](https://www.php.net/manual/en/mysqli.insert-id.php) function, not by reading all the rows from the table. – Progman Jun 13 '20 at 13:39

0 Answers0