未定义的变量,即使我定义了它

时间:2019-03-20 08:29:33

标签: php mysqli

  

[2019年3月20日04:24:48 America / New_York] PHP注意:未定义的变量:第244行的/home/wwwrsfcrm/public_html/airportextras/admin/advance-settings.php中的start_date
  [2019年3月20日04:24:48 America / New_York] PHP注意:未定义的变量:第246行的/home/wwwrsfcrm/public_html/airportextras/admin/advance-settings.php中的end_date

这是我的代码

<?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>

1 个答案:

答案 0 :(得分:0)

解决方案1: 在While / if / else之前:

$start_date = $end_date = NULL;

在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";
}?>

解决方案2: 仅在html中:

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