1
Code:
Editnot
<?php
include('../connection_open.php');
include_once ('../controller/NotControle.php');
include_once ('../model/Not.php');
include_once ('../DAO/NotDAO.php');
$controller = new Notifica($conn);
$id = "";
$InAtivo = "";
$DtInicio = "";
$DtFim = "";
$DsMsg = "";
if(!empty($_GET['id'])){
$id = $_GET['id'];
$results = $controller->listar($id);
$InAtivo = $results->getativo();
$DtInicio = $results->getini();
$DtFim = $results->getfim();
$DsMsg = $results->getmsg();
}
?>
<html>
<body>
<form action="../controller/NotPrecontrole.php" method="POST" onsubmit="return valid();">
<div class="row">
<input type="hidden" name="id" value="<?php echo $id; ?>"/>
<input type="text" name="DsMsg" value="<?php echo $DsMsg; ?>"/>
<input type="submit" class="round success small button" value="Aplicar"/>
<a class="round secondary small button" href="Home.php">Voltar</a>
</div>
</form>
</body>
</html>
Notprecontrole
<?php
include_once ('../connection_open.php');
include_once ('../model/Not.php');
include_once ('NotControle.php');
include_once ('../DAO/NotDAO.php');
$id = $_POST['id'];
$InAtivo = $_POST['InAtivo'];
$DtInicio = $_POST['DtInicio'];
$DtFim = $_POST['DtFim'];
$DsMsg = $_POST['DsMsg'];
$objNot = new Not();
$objNot->setid($id);
$objNot->setativo($InAtivo);
$objNot->setini($DtInicio);
$objNot->setfim($DtFim);
$objNot->setmsg($DsMsg);
$controller = new Notifica($conn);
if (!empty($id)){
$objNot->setid($id);
$controller->editar($objNot);
}
header ("location: ../view/home.php?id=".$id);
include_once ('../connection_close.php');
?>
Notcontrol
<?php
class Notifica{
private $conn;
public function __construct($connec){
$this->conn = $connec;
}
public function editar(Not $objNot){
$dao = new NotDAO($this->conn);
return $dao -> editar($objNot);
}
public function listar($id){
$dao = new NotDAO($this->conn);
return $dao -> listar($id);
}
public function ListaNot(){
$dao = new NotDAO($this->conn);
return $dao -> ListaNot();
}
}
?>
Notdao
<?php
class NotDAO{
private $conn;
public function __construct($connection) {
$this->conn = $connection;
}
public function ListaNot(){
$results = array();
$stmt = $this->conn->prepare('SELECT * FROM esp35399');
$stmt->execute();
if($stmt) {
while($row = $stmt->fetch(PDO::FETCH_OBJ)) {
$not = new Not();
$not->setid($row->ID);
$not->setativo($row->InAtivo);
$not->setini($row->InAtivo);
$not->setfim($row->DtFim);
$not->setmsg($row->DsMsg);
$results[] = $not;
}
}
return $results;
}
public function editar(Not $not){
$this->conn->beginTransaction();
try {
$stmt = $this->conn->prepare(
'UPDATE esp35399 SET DsMsg = :DsMsg, InAtivo = :InAtivo, DtInicio = :DtInicio, DtFim = :DtFim WHERE ID = :ID'
);
$stmt->bindValue(':ID', $not->getid(), PDO::PARAM_INT);
$stmt->bindValue(':InAtivo', $not->getativo(), PDO::PARAM_INT);
$stmt->bindValue(':DtInicio', $not->getini(), PDO::PARAM_INT);
$stmt->bindValue(':DtFim', $not->getfim(), PDO::PARAM_INT);
$stmt->bindValue(':DsMsg', $not->getmsg(), PDO::PARAM_STR);
$stmt->execute();
$this->conn->commit();
}
catch(Exception $e) {
$this->conn->rollback();
}
}
public function listar($id){
$not = new Not();
$stmt = $this->conn->prepare(
'SELECT * FROM esp35399 WHERE ID = :ID'
);
$stmt->bindValue(':ID', $id, PDO::PARAM_INT);
$stmt->execute();
if($stmt) {
while ($row = $stmt->fetch(PDO::FETCH_OBJ)) {
$not->setid($row->ID);
$not->setativo($row->InAtivo);
$not->setini($row->DtInicio);
$not->setfim($row->DtFim);
$not->setmsg($row->DsMsg);
}
}
return $not;
}
}
?>
Not
class Not{
private $id;
private $InAtivo;
private $DtInicio;
private $DtFim;
private $DsMsg;
public function setid($id){
$this->id = $id;
}
public function getid(){
return $this->id;
}
public function setativo($InAtivo){
$this->InAtivo = $InAtivo;
}
public function getativo(){
return $this->InAtivo;
}
public function setini($DtInicio){
$this->DtInicio = $DtInicio;
}
public function getini(){
return $this->DtInicio;
}
public function setfim($DtFim){
$this->DtFim = $DtFim;
}
public function getfim(){
return $this->DtFim;
}
public function setmsg($DsMsg){
$this->DsMsg = $DsMsg;
}
public function getmsg(){
return $this->DsMsg;
}
Home
foreach ($controller->ListaNot() as $objNot){
<p><?php echo $objNot->getmsg(); ?></p>
echo '<a href="editNot.php?id=' . $objNot->getid() . '">Editar</a>';
}
The problem is that when editing something on input "DsMsg"
on the page editNot is not changing in the bank and keeps returning me the same thing on echo
on the page home within the foreach
. I have not identified the error yet. It seems that the edit function in DAO is not working, but the others work perfectly. Some help ?
Debug, print the query that was executed to save the value. The query will show where the problem is, if the correct value is coming.
– Duque
I gave one
print_r($objNot);
in Notprecontrole and returns to me what I edited ininput DsMsg
, Until there arrives because the bank does not edit and so does not appear inecho $objNot->getmsg();
in the home already edited.– KevinF
Update condition is being met ?
– Duque
It doesn’t work, the input data reaches even in the precontrol after then nothing happens.
– KevinF
Solve the notices and do new tests.
– Duque
Now I returned these errors in the precontrol:
Notice: Undefined index: InAtivo in C:\xampp\htdocs\controller\NotPrecontrole.php on line 9
Notice: Undefined index: DtInicio in C:\xampp\htdocs\controller\NotPrecontrole.php on line 10
Notice: Undefined index: DtFim in C:\xampp\htdocs\controller\NotPrecontrole.php on line 11
– KevinF
Okay, I got it, but it’s still the same.
– KevinF
Print the query and show it to us as an example here.
– Duque
Which query do you need ? I don’t understand. What kind of information do you want to help me ?
– KevinF
I would like to see the sql query you used to save the edited records.
– Duque
Only sql query that use is that ai of the edit function is this you need ?
– KevinF