Ciao Ragazzi è incredibile non riesco a trovare il problema in questo semplicissimo programma:
Riesco a visualizzare le textbox contenenti i dati , ma non riesco ad aggiornare il DB:
l output mi da sempre Non trasmesso;
e l HTML:
Riesco a visualizzare le textbox contenenti i dati , ma non riesco ad aggiornare il DB:
l output mi da sempre Non trasmesso;
PHP:
//File: allievo.php
public function stored(){
//update query
$query = "UPDATE ". $this->table_name ."SET stato = 'STORED' WHERE idAllievo = :id";
//prepare the query
try{
$stmt = $this->conn->prepare($query);
}catch (Exception $e) {
echo 'Problema di prepare', $e->getMessage(), "\n";
}
//echo($this->idAllievo);
try{
// unique ID of record to be edited
$stmt->bindParam(':id', $this->idAllievo);
}catch (Exception $e) {
echo 'Problema di binding', $e->getMessage(), "\n";
}
// execute the query
if($stmt->execute()){
echo("OK");
}else{
echo("Non Trasmesso");
}
}
e l HTML:
Codice:
// include classes
include_once '../../config/database.php';
include_once '../../objects/allievo.php';
// get database connection
$database = new Database();
$db = $database->getConnection();
//var_dump($db);
// initialize objects
$allievo = new Allievo($db);
// set page title
$page_title = "<a href='read_allievi.php'>Allievi</a> / Stored allievo";
// include page header HTML
include_once "../layout_head.php";
echo "<div class='col-md-12'>";
// get allievo id on the URL parameter
$allievo_id=isset($_GET['id']) ? $_GET['id'] : die('Missing allievo ID.');
// check if value was posted
if($_POST){
// set allievo id property
$allievo->idAllievo=$allievo_id;
/*---------------------------------------------------------------------------------------------------
// set posted values to allievo properties
$allievo->cognome=$_POST['cognome'];
$allievo->nome=$_POST['nome'];
$allievo->stato=$_POST['stato'];
$allievo->id=$allievo_id;
// update allievo
if($allievo->update()){
$allievo->readOne();
/*
// get currently logged in allievo first name
$user->id=$_SESSION['user_id'];
$allievo->readOne();
// change saved firstname
$_SESSION['firstname']=$user->firstname;
---------------------------------------------------------------------------------------------------*/
//update allievo
if($allievo->stored()){
// tell allievo it was updated
echo "<div class='alert alert-success'>L'allievo è stato modificato</div>";
}
// unable to edit allievo
else{
echo "<div class='alert alert-danger' role='alert'>E' stato impossibile modificare l'allievo.</div>";
}
}
// set allievo id property
$allievo->idAllievo=$allievo_id;
// read allievo details
$allievo->readOne();
?>
<!-- HTML form to update allievo -->
<form action='stored_allievo.php?id=<?php echo $allievo_id; ?>' method='post' id='stored-allievo'>
<table class='table table-hover table-responsive table-bordered'>
<tr>
<td class='width-30-percent'>Cognome</td>
<td><input type='text' name='cognome' value="<?php echo $allievo->cognome; ?>" class='form-control' required></td>
</tr>
<tr>
<td>Nome</td>
<td><input type='text' name='nome' value="<?php echo $allievo->nome; ?>" class='form-control' required></td>
</tr>
<tr>
<td>Stato</td>
<td>
<input type="text" name="stato" value="<?php echo $allievo->stato;?>">?
</td>
</tr>
<tr>
<td></td>
<td>
<button type="submit" class="btn btn-primary">
<span class="glyphicon glyphicon-edit"></span> Stored allievo
</button>
</td>
</tr>
</table>
</form>
<?php
echo "</div>";
// include page footer HTML
include_once "../layout_foot.php";
?>