2
Good staff, had already made a topic here about it and solved it right away, but then I noticed that when I fixed this problem I got another one. Here is the code:
<?
error_reporting(0);
require('cdn/inc/header.php');
if(isset($_SESSION['user_data'])):
$user_level = $_SESSION['user_data']['level'];
switch($user_level):
case 1:
case 2:
case 3:
case 5:
case 8:
case 9:
$query = "SELECT * FROM testes WHERE ID = :ID";
$result = $db->prepare($query);
$result->execute(array(':ID' => $_REQUEST['ID']) );
if ($row = $result->fetch(PDO::FETCH_ASSOC)) {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input id="Title" type="text" name="Title" value="<?php echo $row['Title']; ?>" required />
<input type="hidden" name="ID" value="<?php echo $row['ID']; ?>" />
<input type="Submit" name="Submit" value="Salvar alterações" />
</form>
<?
}
elseif (isset($_POST['Submit'])) {
$ID = $_POST['ID'];
$Title = $_POST['Title'];
$queryupdate = "UPDATE testes SET Tile = :Title WHERE ID= :ID";
$q = $db->prepare($queryupdate);
$q->execute(array(":Title" => $Title));
header ('Location: edit.php');}
else {
$stmt = $db->query("SELECT * FROM testes ORDER BY STR_TO_DATE(Date, '%d-%m-%y') ASC, Title ASC);
$stmt->execute();
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);?>
<div id="user-bar" style="background: #C16011;">
<i>
<a href="add.php">Adicionar</a>
</i>
</div>
<br />
<br />
<?
foreach($data as $index => $row) {
$className = $index % 2 == 0 ? "class" : "class-1" ?>
<form action="" name="Inser" method="post">
<div class="selector">
<input name="selector[]" class="selector" type="checkbox" value="<?php echo $row['ID']; ?>" />
</div>
<a href="edit.php?ID=<? echo $row['ID']; ?>"><? echo $row['Title']; ?></a>
</div>
</h6>
</div>
<?
}
if(empty($data)){?>
<div class="no-data">
DATA/HORA: <b><?echo date("d-m-Y");?></b>/<b><? echo date("H:i");?></b>
<br />
SEM NADA
</div>
<?}
else
{?>
<div class="btn-padding">
<div class="btn-group dropup pull-right">
<button type="button" class="btn btn-primary">Seleciona uma acção</button>
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
<li><a href="" class="selectall-button" onClick="return false;">Selecionar tudo / Nao selecionar</a></li>
<li class="divider"></li>
<li><a href="#" type="submit" class="delete-button"onclick="javascript:document.Insert.submit();">Eliminar</a></li>
</ul>
</div>
</div>
</form>
<?
}
$edittable=$_POST['selector'];
$N = count($edittable);
for($i=0; $i < $N; $i++)
{
$result = $db->prepare("DELETE FROM testes WHERE ID= :ID");
$result->bindParam(':ID', $edittable[$i]);
$result->execute();
header ('Location: edit.php');
}
}
?>
<br />
<br />
<center>
<small>TESTE.</small>
</center>
</body>
</html>
<?
break;
endswitch;
else:
header( 'Location: ../ ');
endif;
?>
Here’s how I opened the another topic, I mean, when I do submit
does not update the database, but if I change the elseif
for if
, when I go to edit the post is the list I have in the table below the edit.
Is there any way to fix this?
I already did and the error remains, only from the refresh page but does not update anything
– thecreator
What error? could put the message
– rray
No error, is checking it now, just refresh and no message appears ..
– thecreator
put this on top:
error_reporting(E_ALL);
ini_set('display_errors', 1);
and even then I don’t get error message– thecreator
@thecreator, maybe the problem is this line
if(isset($_SESSION['user_data'])):
of a $_SESSION scan or print_r– rray
Array ( [loggedin] => 1 [username] => testuser1 [user_data] => Array ( [memberID] => 7 [username] => testuser1 [password] => $2y$10$t7q7XNa00.8ikOQ2lwZP7OF.1mlv4P9jlNvELuNWSSq0jacWIM.ou [email] => [email protected] [level] => 1 [active] => Yes [avatar] => [resetToken] => [resetComplete] => No [color] => CE9715 ) )
– thecreator
I decided to put
if
instead ofifelse
and close the if after thesubmit
– thecreator
now I have another question, can go to chat?
– thecreator
@thecreator can speak
– rray
for example, I have a 'a href' that from Submit to form, as I get it to give Submit and to appear a confirmation message and only if I give ok is that it ends the accao?
– thecreator
@thecreator, you need to call a javascript function in href. What shows this message is the
confirm()
– rray