-1

I've been trying to solve this problem of mine for 2 days now and I can't think of anything else anymore.
Undefined variable on lines 126, 129 and 132.
I've been trying to use isset or empty to somewhat get the out put, but it doesn't seem to work.

Hope you guys can help me with this :)

<body>
    <head>
        <script src="js/jquery.js"></script>
        <script src="js/bootstrap.min.js"></script>
        <script src="js/smoothscroll.js"></script>
        <script src="js/resetOnClick.js"></script>

        <link href="css/bootstrap.min.css" rel="stylesheet"/>
        <link href="css/styles.css" rel="stylesheet"/>  
        <link href="css/notifbox.css" rel="stylesheet"/>
    </head>

    <center><label class="control-label" style="font-size:30px">Reservation</label></center>
    <center><label class="control-label" style="font-size:15px">Edit Record</label></center>
    <br/>
    <br/>

    <?php
    //$id = isset($_GET['id'])? $_GET['id'] : "";
    if(isset($_POST['editreservation']))
    {
        include('config/config1.php');
        $rsvtn = $_POST['editreservation'];
        $sel = "SELECT venue.venue_type, reservation.reservation_date, reservation.reservation_time
        FROM venue
        INNER JOIN reservation ON reservation.Venue_idVenue = venue.idVenue where idReservation = '2';";
        $query = mysqli_query($conn,$sel);
        echo $sel;
        if(!$editreservation)
{
    printf("Error: %s\n", mysqli_error($conn));
    exit();
}

        while($detail = mysqli_fetch_array($query))
        {   
            $rid = $detail['idReservation'];
            $ven = $detail['venue_type'];
            $res_t = $detail['reservation_date'];
            $res_d = $detail['reservation_time'];
            echo $ven;
    ?>

    <form class="form-horizontal form-label-left" method="post">

        <div class="form-group">
                <!--BACK Button-->
                <a href="Reservation Records.php" class="col-md-6 col-md-offset-3" style="font-size:20px">Back</a>
                <!--BACK Button-->
        </div>
        <!--<input type="hidden" name="submitted" value="true"/>-->
            <div class="item form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12">Venue<span class="required">*</span></label>
                    <div class="col-md-6 col-sm-6 col-xs-12">
                        <input id="venue_type" data-content="<?php echo $ven;?>" class="form-control col-md-7 col-xs-12" name="venue_type" placeholder="Venue" required="required" type="text" value="<?php echo $ven;?>">
                    </div>          
            </div>

            <div class="item form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Reservation Date<span class="required">*</span>
                </label>
                <div class="col-md-6 col-sm-6 col-xs-12">
                    <input id="reservation_date" data-content="<?php echo $res_d;?>" class="form-control col-md-7 col-xs-12" name="reservation_date" placeholder="Reservation Date" required="required" type="date" value="<?php echo $res_d;?>">
                </div>
            </div>

            <div class="item form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Reservation Time<span class="required">*</span></label>
                <div class="col-md-6 col-sm-6 col-xs-12">
                    <input id="reservation_time" data-content="<?php echo $res_t;?>" class="form-control col-md-7 col-xs-12" name="reservation_time" placeholder="Reservation Time" required="required" type="time" value="<?php echo $res_t;?>">
                </div>
            </div>



            <div class="ln_solid"></div>
            <div class="form-group">
                <div class="col-md-6 col-md-offset-3">
                    <input type="hidden" name="updRsvtn" value="<?php echo $detail['idReservation'];?>">
                    <input type="submit" class="btn btn-primary submits" value="Save Edited" onClick="Reservation Records.php" >
                </div>
            </div>  
            <?php
        } 
    }   
    ?>
    <?php
    if(isset($_POST['updRsvtn']))
        {   
            include('config/config1.php');



            $ven = $_POST['venue_type'];
            $res_d = $_POST['reservation_date'];
            $res_t = $_POST['reservation_time'];



            if(!mysqli_query($conn,"UPDATE reservation, venue SET venue_type = '$ven', reservation_date = '$res_d', reservation_time = '$res_t' WHERE idReservation = '$id'"))
            {
                echo "Not Queried: Wrong variables !";
            }   
            else
            {
                header("Location: Reservation Records.php");

            }
            mysqli_close($conn);
        }
    ?>  
    </form>

    <table class = "notif pos">
      <thead>
        <tr>
          <th><center/><b>*Old Record</b></th>
        </tr>
      </thead>

      <tbody>
        <tr>
          <td><center/><?php echo $ven;?></td>
        </tr>
        <tr>
          <td><center/><?php echo $res_d;?></td>
        </tr>
        <tr>
          <td><center/><?php echo $res_t;?></td>
        </tr>
      </tbody>
    </table>


</body>

Jake Oliva
  • 55
  • 2
  • 2
    Please specify which are the lines 126, 129 and 132 in your code? – RK12 Mar 15 '16 at 08:52
  • 1
    You don't seem to understand the problem. On that line, that variable doesn't exist. Why does it not exist? Because you have not defined it before. Why has it not been defined before? Because all the `if` and `while` conditions that it depends on where `false` and it has never been declared. Figure out why, and/or change your logic to make sure it's defined, and/or don't attempt to output it when it's not defined. – deceze Mar 15 '16 at 08:58
  • It means you are getting errors for : $ven; $res_d; $res_t – Irshad Khan Mar 15 '16 at 08:59
  • @deceze Thanks, dude! Its all good now. Changed my if and while statements. – Jake Oliva Mar 15 '16 at 09:17

3 Answers3

0

One of the undefined variables is, I assume $editreservation. If we look at some of the snipped code you do the following:

if(isset($_POST['editreservation'])){
    //$_POST['editreservation'] is set!
    $rsvtn = $_POST['editreservation'];
    //$rsvtn is set
    if(!$editreservation){
        //$editreservation has *not* been set by your code.
    }
}

Because $editreservation hasn't been declared anywhere you get the undefined variable notice.

Jim
  • 22,354
  • 6
  • 52
  • 80
-1

Variables are not "set" at that point (scope). If you just want to pass that error, try:

<td><center/><?php echo isset($ven) ? $ven : '' ?></td>
<td><center/><?php echo isset($res_d) ? $res_d : '' ?></td>
<td><center/><?php echo isset($res_t) ? $res_t : '' ?></td>
KiwixLV
  • 226
  • 1
  • 5
-1

Try this if you want to avoid errors

<tr>
    <td><center/><?php echo @$ven; ?></td>
</tr>
<tr>
    <td><center/><?php echo @$res_d; ?></td>
</tr>
<tr>
    <td><center/><?php echo @$res_t; ?></td>
</tr>

Now replace above section with your code and check.

Irshad Khan
  • 5,670
  • 2
  • 44
  • 39