-3

[20-Mar-2019 04:24:48 America/New_York] PHP Notice: Undefined variable: start_date in /home/wwwrsfcrm/public_html/airportextras/admin/advance-settings.php on line 244
[20-Mar-2019 04:24:48 America/New_York] PHP Notice: Undefined variable: end_date in /home/wwwrsfcrm/public_html/airportextras/admin/advance-settings.php on line 246

Here is my code

<?php include('inc/header.php'); ?>
<?PHP
   session_start();
   if($_SESSION['username']=='' && $_SESSION['password']==''){
    header('Location: index');

}
?>

<?php include('inc/sidebar.php'); ?>
<?php 
$currentid = $_SESSION['aid'];
$con = mysqli_connect("localhost","root","password","database");

//Check connection
if (mysqli_connect_errno())
{
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}


 $query = "SELECT * FROM disabled_dates WHERE agent_id = '$currentid'";
 $result = mysqli_query($con, $query);
 if(mysqli_num_rows($result) > 0)
 {
    while($row = mysqli_fetch_array($result))
    {
        $start_date = $row['start_date'];
        $end_date = $row['end_date'];                   
    }
  }
?>


    <div class="col-sm-9 col-sm-offset-3 col-lg-10 col-lg-offset-2 main">           
        <div class="row">
            <ol class="breadcrumb">
                <li><a href="#"><svg class="glyph stroked home"><use xlink:href="#stroked-home"></use></svg></a></li>
                <li class="active">Icons</li>
            </ol>
        </div><!--/.row-->

        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header"></h1></h1>
            </div>
        </div><!--/.row-->


        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">Airport Parking Advance Settings</div>
                    <div class="panel-body">
                        <div class="col-md-12">
                        <button class="btn btn-primary" data-toggle="modal" data-target="#cpbd" id="link_bt">Change Price by Date</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                        <button class="btn btn-primary" data-toggle="modal" data-target="#soobd" id="link_bt">Service Disable by Date</button>      
                            <!--Change Price by Date Modal -->
<div id="cpbd" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Change Prices by Date</h4>
      </div>
      <div class="modal-body">
        <p>
             <form  role="form" method="post" action="changed-prices" id="sign_in" autocomplete="off">

                        <div class="row">

                            <div class="col-md-12 col-sm-12 col-xs-12">
                                <div class="form-group plates-options">
                                    <label>Change Prices by Date</label>
                                    <input type="date" id="check_out" name="sdate" placeholder="Date" class="form-control" aria-required="true" required>

                               </div>
                            </div>
                            <div class="col-md-6 col-sm-6 col-xs-6">
                                <div class="form-group">
                                    <label>Day Price</label>
                                    <input name="dayprice" type="text" class="form-control" placeholder="Day Price" required>

                                   </div>
                            </div>

                           <div class="col-md-6 col-sm-6 col-xs-6">
                                <div class="form-group">
                                    <label>Additional Day Price</label>
                                    <input name="addprice" type="text" class="form-control" placeholder="Additional Day Price" required>

                                   </div>
                            </div>
                            <div class="col-md-12 col-sm-12 col-xs-12">
                                 <h3>Prices for Meet & Greet</h3>
                                  </div>
                            <div class="col-md-6 col-sm-6 col-xs-6">

                                <div class="form-group">
                                    <label>Fixed Price</label>
                                    <input name="mgfixprice" type="text" class="form-control" placeholder="Fixed Price" required>

                                   </div>
                            </div>


                            <div class="col-md-6 col-sm-6 col-xs-6">
                                <div class="form-group">
                                    <label>Flexible Price</label>
                                    <input name="mgflexprice" type="text" class="form-control" placeholder="Flexible Price" required>

                                   </div>
                            </div>
                            <div class="col-md-12 col-sm-12 col-xs-12">
                              <h3>Prices for Park & Ride</h3>   
                                </div>

                           <div class="col-md-6 col-sm-6 col-xs-6">

                                <div class="form-group">
                                    <label>Fixed Price</label>
                                    <input name="prfixprice" type="text" class="form-control" placeholder="Fixed Price" required>

                                   </div>
                            </div>


                            <div class="col-md-6 col-sm-6 col-xs-6">
                                <div class="form-group">
                                    <label>Flexible Price</label>
                                    <input name="prflexprice" type="text" class="form-control" placeholder="Flexible Price" required>

                                   </div>
                            </div>


                        </div><!-- End row -->

                        <div class="row">

                                   <div class="col-md-12 col-sm-12">
                                   <div class="form-group">
                                   <input type="submit" name="pricedate" value="Submit" class="btn btn-primary" id="price-date">
                                   </div>
                                   </div>
                             </div>
                                  </form>

        </p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>


<!--Add Off Hours to take booking Modal -->
<div id="soobd" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Service Disable by Date</h4>
      </div>
      <div class="modal-body">
        <p>
             <form  role="form" method="post" action="service-disable" id="sign_in" autocomplete="off">

                        <div class="row">
                        <h3>Service Disable by Date</h3>
                            <div class="col-md-6 col-sm-6 col-xs-6">
                                <div class="form-group plates-options">
                                    <label>Start Date</label>
<input class="form-control" data-date-format="M d, D" type="date" name="sdate" placeholder="Date" required>

                               </div>
                            </div>

                         <div class="col-md-6 col-sm-6 col-xs-6">
                                <div class="form-group plates-options">
                                    <label>End Date</label>
<input class="form-control" data-date-format="M d, D" type="date" name="edate" placeholder="Date" required>

                               </div>
                            </div>


                        </div><!-- End row -->

                        <div class="row">

                                   <div class="col-md-12 col-sm-12">
                                   <div class="form-group">
                                   <input type="submit" name="specificdate" value="Submit" class="btn btn-primary" id="hours">
                                   </div>
                                   </div>
                             </div>
                                  </form>

        </p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>  <br><br>                                                    

                      <div class="table-responsive">
                        <table class="table table-bordered">
                            <tr>




                                <h3>Your Service's Disable Dates </h3>


                         <tbody>       


        </tr>
        <tr>
            <th>Start Date</th>
             <th>End Date</th>
            </tr>



                            <tr>

                                <td> <?php echo $start_date; ?> </td>

                               <td> <?php echo $end_date; ?></td> 


                            </tr>      

                           </tbody> 

                        </table>
                        </div>                  





                            </div>

                    </div>
                </div>
            </div><!-- /.col-->
        </div><!-- /.row -->

    </div><!--/.main-->


<script src="js/jquery-1.11.1.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/chart.min.js"></script>
    <script src="js/chart-data.js"></script>
    <script src="js/easypiechart.js"></script>
    <script src="js/easypiechart-data.js"></script>
    <script src="js/bootstrap-datepicker.js"></script>

<link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.12.1/themes/pepper-grinder/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/dubrox/Multiple-Dates-Picker-for-jQuery-UI/master/jquery-ui.multidatespicker.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script src="https://cdn.rawgit.com/dubrox/Multiple-Dates-Picker-for-jQuery-UI/master/jquery-ui.multidatespicker.js"></script>
<form name="select-multiple">

        <script>

    $("#addday").change(function () {
   $("#adddayprice").toggle();
});
        $("#mg").change(function () {
   $("#mgprice").toggle();
   $("#mgprice2").toggle();
});

$("#pr").change(function () {
   $("#prprice").toggle();
   $("#prprice2").toggle();
});

        !function ($) {
            $(document).on("click","ul.nav li.parent > a > span.icon", function(){        
                $(this).find('em:first').toggleClass("glyphicon-minus");      
            }); 
            $(".sidebar span.icon").find('em:first').addClass("glyphicon-plus");
        }(window.jQuery);

        $(window).on('resize', function () {
          if ($(window).width() > 768) $('#sidebar-collapse').collapse('show')
        })
        $(window).on('resize', function () {
          if ($(window).width() <= 767) $('#sidebar-collapse').collapse('hide')
        })
    </script>   


</body>

</html>
Rayn
  • 1
  • 4
  • Please remove all irrelevant code. – M. Eriksson Mar 20 '19 at 08:32
  • You have to init your variable BEFORE the if/else and While, because if you have no result in your query like it seems to be the case, then you have an error. OR you can add a condition where you use the variables like `if(isset($start_date)){echo ...}` – Eiji Mar 20 '19 at 08:32
  • Be careful, you're sharing private information in your code examples. Make sure to change these credentials. – syntax-punk Mar 20 '19 at 08:34
  • How can I initialize these variables before if condition because I am getting these values from database – Rayn Mar 20 '19 at 08:34
  • Just throwing tons of code with an implicit "do my work" is not what StackOverflow is for. Please read [ask] – Pinke Helga Mar 20 '19 at 08:35
  • Oh Thank you very much @voogieJames – Rayn Mar 20 '19 at 08:36
  • Create varibales outside of your loop (higher in your code) and then set their values in the loop. – syntax-punk Mar 20 '19 at 08:37
  • Your variables `$start_date` and `$end_date ` is defined conditionally. They may not always be defined if the query returned no results. – Qirel Mar 20 '19 at 08:39
  • but I want to get these values from the database so when I got these values from database after that I put these values to variables – Rayn Mar 20 '19 at 08:45
  • But WHAT IF the value are not coming? That's the case, and then you have an Error. – Eiji Mar 20 '19 at 08:52
  • Also worth checking https://stackoverflow.com/questions/3553698/php-should-i-call-exit-after-calling-location-header as you redirect at the start but the script will carry on running. – Nigel Ren Mar 20 '19 at 09:02

1 Answers1

1

Solution 1 : Before the While/if/else :

$start_date = $end_date = NULL;

In the html :

<?php echo (!empty($end_date))?$end_date:"0000/00/00"; ?>
//same with start_date

//or

<?php if(!empty($end_date)){
    echo $end_date;
}else{
    echo "0000/00/00";
}?>

Solution 2 : Only in the html :

<?php echo (isset($end_date))?$end_date:"0000/00/00"; ?>
//same with start_date
Eiji
  • 454
  • 6
  • 15