-1

I have some troubles with visualization of the date in a query with php. Here is the code:

<?php
$hostname = "localhost";
$username = "root";
$password = "";
$dbname   = "alternanza";
// connessione al server sql
$conn     = mysqli_connect($hostname, $username, $password, $dbname);
if (!$conn) {
    die("errore nella connessione");
} else {
    echo "connessione avvenuta correttamente <Br/>";
}
// recupero dati passati dal form 
$nome    = $_POST["nome"];
$cognome = $_POST["cognome"];
$dal     = $_POST["dal"];
$al      = $_POST["al"];

$query     = "select NomeS, CognomeS, Specializzazione, Denominazione 
from studente, azienda, attivitàformativa 
where CodFiscaleS=KCodFiscaleS and CodAzienda=KodAzienda and Data_inizio='$dal' 
and Data_fine='$al' and CognomeS='$cognome' and NomeS='$nome'";
$risultato = mysqli_query($conn, $query);
if (!$risultato) {
    echo " errore di comando <br/>";
    exit();
}
while ($riga = mysqli_fetch_array($risultato))
    if ($riga) {
        echo "nome: " . $riga['NomeS'] . " <br/>";
        echo "cognome: " . $riga['CognomeS'] . " <br/>";
        echo "periodo stage dal: " . $riga['Data_inizio'] . " <br/>";
        echo "al: " . $riga['Data_fine'] . " <br/>";
        echo "presso azienda: " . $riga['Denominazione'] . " <br/>";
        echo "con specializzazione: " . $riga['Specializzazione'] . " <br/>";
    }
mysqli_close($conn);
echo " connessione chiusa";
?>

The errors I viewed are:

Notice: Undefined index: Data_inizio(date) in C:\xampp\htdocs\scuola18\attestato.php on line 38 periodo stage dal:

Notice: Undefined index: Data_fine in C:\xampp\htdocs\scuola18\attestato.php on line 39 al:

Do you know something about?

Dave
  • 3,073
  • 7
  • 20
  • 33
  • 1
    Possible duplicate of ["Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP](https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-and-notice-undefined) – Zain Farooq May 16 '19 at 10:43
  • You have missed `Data_fine` and `Data_inizio` in your select query – Zain Farooq May 16 '19 at 10:48

1 Answers1

0

You have missed Data_fine and Data_inizio in your select query. Your select query should look like this

select NomeS, Data_fine, Data_inizio,  CognomeS, Specializzazione, Denominazione 
from studente, azienda, attivitàformativa 
where CodFiscaleS=KCodFiscaleS and CodAzienda=KodAzienda and Data_inizio='$dal' 
and Data_fine='$al' and CognomeS='$cognome' and NomeS='$nome'

However, I suggest you to use parepared statements to prevent from sql injections

Zain Farooq
  • 2,956
  • 3
  • 20
  • 42