'How to use an if statement with base_url() in PHP?

I want to insert in my db the date of creation of an object form only if the base_url is equal to insertobject ! to be more clear i dont want to insert the date if i'm in update mode my code right now is inserting the date even when i'm updating.

<form method="post" id="object_add" class="card" action="<?php echo base_url();?>object/<?php echo (isset($objectdetails))?'updateobject':'insertobject'; ?>">

<input type="hidden" id="obj_created_date" name="obj_created_date" value="<?php echo date('Y-m-d H:i:s'); ?>">

</form>

Here is my main code :

 <form method="post" id="vehicle_add" class="card" action="<?php echo base_url();?>vehicle/<?php echo (isset($vehicledetails))?'updatevehicle':'insertvehicle'; ?>">
                <div class="card-body">


                  <div class="row">
                    <?php if(isset($vehicledetails)) { ?>
                   <input type="hidden" name="v_id" id="v_id" value="<?php echo (isset($vehicledetails)) ? $vehicledetails[0]['v_id']:'' ?>" >
                    <?php } ?>
                    <div class="col-sm-6 col-md-4">
                        <label class="form-label">Registration Number</label>
                      <div class="form-group">
                        <input type="text" name="v_registration_no" id="v_registration_no" class="form-control" placeholder="Registration Number" value="<?php echo (isset($vehicledetails)) ? $vehicledetails[0]['v_registration_no']:'' ?>">
                      </div>
                    </div>
                    <div class="col-sm-6 col-md-4">
                        <label class="form-label">Vehicle Name</label>
                      <div class="form-group">
                        <input type="text" name="v_name" id="v_name" class="form-control" placeholder="Vehicle Name" value="<?php echo (isset($vehicledetails)) ? $vehicledetails[0]['v_name']:'' ?>">
                      </div>
                    </div>
                    <div class="col-sm-6 col-md-4">
                      <div class="form-group">
                        <label class="form-label">Model</label>
                        <input type="text" name="v_model" value="<?php echo (isset($vehicledetails)) ? $vehicledetails[0]['v_model']:'' ?>" class="form-control" placeholder="Model">
                      </div>
                    </div>
 <input type="hidden" id="obj_created_date" name="obj_created_date" value="<?php echo date('Y-m-d H:i:s'); ?>">

    </form>

Any hero to save my day ??



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source