I am doing an internship in a company and I am developing an application that can manage the fleet of vehicles of this company, people can make reservations, see reservations, etc. And I have a page where people can see the reservations made. On my laptop where I'm using Linux(Antergos), I'm using Lamp to develop my application. In my Linux everything is working fine but when I tried the code in Windows using Wamp the page that lets you view the reservations is not working properly. A fact aside, I just started PHP since March so i m sorry if the code looks very rudimentary.
Here's how it should work(in Linux):
Working:
The error that gives is this:
Notice: Undefined index: data_de_reserva in C: \ wamp64 \ www \ 1 \ ver_reservas.php on line 65 Call Stack #TimeMemoryFunctionLocation 10.0014255064 {main} () ... \ ver_reservas.php: 0 "/>
This is where i get my error:
<input name="calendario" type="text" id="calendario" size="10" autocomplete="off" value="<?php echo $_REQUEST["data_de_reserva"]; ?>" />
And here is the rest of my code:
<?php
include 'connect_database.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="pt-pt">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Gestão de Viaturas</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js">
</script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Ek+Mukta">
<link rel="icon" href="_imagens/favicon2.png">
<style>
body, td {
font-size:12px;
}
</style>
</head>
<body>
<div class="logo">
<img src="_imagens/logo2.jpg" alt="logo">
</div>
<nav class="menu">
<ul class="clearfix">
<li><a href="home.php">Bem vindo <u><?php echo getenv('USERNAME');?></u></a></li>
<li><a href="#">Reservas <span class="arrow">▼</span></a>
<ul class="sub-menu">
<li><a href="reservas.php">Fazer Reservas</a></li>
<li><a href="ver_reservas.php">Ver Reservas</a></li>
</ul>
</li>
<li><a href="#">Adminstração<span class="arrow">▼</span></a>
<ul class="sub-menu">
<li><a href="apagar_reservas.php">Apagar Reservas</a></li>
<li><a href="adicionar.php">Adicionar Carros</a></li>
</ul>
</li>
<li><a href="#">About<span class="arrow">▼</span></a>
<ul class="sub-menu">
<li><a href="#">Saida do carro</a></li>
<li><a href="#">Entrada do carro</a></li>
</ul>
</li>
</ul>
</nav>
</br>
</br>
</br>
</br>
<div id="super">
<div class="datagrid">
</br>
<form id="search_form" name="search_form" method="post" action="ver_reservas.php">
<label for="calendario">Data</label>
<input name="calendario" type="text" id="calendario" size="10" autocomplete="off" value="<?php echo $_REQUEST["data_de_reserva"]; ?>" />
<label>Carro</label>
<select name="carro">
<option value="">--</option>
<?php
$query = "SELECT * FROM reservas GROUP BY carro_usado ORDER BY carro_usado";
$query_result = mysqli_query($con, $query) or die ('request "Could not execute SQL query" '.$query);
while ($row = mysqli_fetch_assoc($query_result)) {
echo "<option value='".$row["carro_usado"]."'".
($row["carro_usado"]==$_REQUEST["carro_usado"] ? " selected" : "").">".$row["carro_usado"]."</option>";
}
?>
</select>
<input type="submit" name="button" id="button" value="Filtrar"/>
</label>
<a href="ver_reservas.php">Limpar</a>
</form>
</br>
<table width="700" border="1" cellspacing="0" cellpadding="4">
<tr>
<td width="110" bgcolor="#CCCCCC"><strong>Nome</strong></td>
<td width="110" bgcolor="#CCCCCC"><strong>Carro</strong></td>
<td width="110" bgcolor="#CCCCCC"><strong>Data</strong></td>
<td width="40" bgcolor="#CCCCCC"><strong>Hora</strong></td>
<td width="40" bgcolor="#CCCCCC"><strong>Hora
Prevista</strong></td>
<td width="290" bgcolor="#CCCCCC">
<strong>Informação</strong></td>
</tr>
<?php
if ($_REQUEST["carro"]<>'') {
$search_carro = " AND
carro_usado='".mysqli_real_escape_string($con, $_REQUEST["carro"])."'";
}
if ($_REQUEST["calendario"]<>'') {
$sql = "SELECT * FROM reservas WHERE data_de_reserva =
'".mysqli_real_escape_string($con, $_REQUEST["calendario"])."'".$search_carro;
} elseif($_REQUEST["calendario"]<>'') {
$sql = "SELECT * FROM reservas WHERE id>0".$search_carro;
} else {
$sql = "SELECT * FROM reservas WHERE DATE(`data_de_reserva`) >= CURDATE()".$search_carro. "ORDER BY data_de_reserva";
}
$sql_result = mysqli_query($con, $sql) or die ('request "Could
not execute SQL query" '.$sql);
if (mysqli_num_rows($sql_result)>0) {
while ($row = mysqli_fetch_assoc($sql_result)) {
?>
<?php $row["data_de_reserva"] = date('d.m.Y', strtotime($row["data_de_reserva"]));
$row["hora"] = date('H:i', strtotime($row["hora"]));
$row["hora_prevista"] = date('H:i', strtotime($row["hora_prevista"]));
?>
<tr>
<td><?php echo $row["nome"]; ?></td>
<td><?php echo $row["carro_usado"]; ?></td>
<td><?php echo $row["data_de_reserva"]; ?></td>
<td><?php echo $row["hora"]; ?></td>
<td><?php echo $row["hora_prevista"]; ?></td>
<td><?php echo $row["informacao"]; ?></td>
</tr>
<?php
}
} else {
?>
<tr><td colspan="6">Nenhum resultado encontrado.</td>
<?php
}
?>
</table>
<script>
$(function() {
var dates = $( "#calendario").datepicker({
defaultDate: "",
changeMonth: true,
numberOfMonths: 1,
dateFormat: 'yy-mm-dd',
onSelect: function( selectedDate ) {
var option = this.id,
instance = $( this ).data( "datepicker" ),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datepicker( "option", option, date );
}
});
});
</script>
</div>
</div>
</body>
</html>