So, in my website, I have a news system which has an option to edit and delete the news the administrator desires.
Well, I got the edit part right by using:
href="noticiaEditarForm.php?id_noticia=<?php echo $id ?>">Editar</a>
And then a $_GET
on the other page.
However, this is not how I desire my editing window. Therefore, I have been exploring a way to send the PHP variable that contains the primary key for the news table (MySQL) to a popup window, using JavaScript. But that's just the thing, it will only return the 1st value it gets from the query... (i.e If I click to edit the 3rd article, it edits my 1st one. Always.)
Here is my current code:
<div class="noticias">
<?php
include('conn/conn.php');
mysql_select_db($bd, $conn);
$resultado = mysql_query("SELECT * FROM noticia INNER JOIN user ON noticia.id_user=user.id_user ORDER BY id_noticia DESC");
while ($linha = mysql_fetch_array($resultado)) {
echo "<h1>" . $linha['titulo'] . "</h1>";
echo "<i>Posted by " .$linha['username']. " on " . "<y>" . $linha['data'] . "</y>" . "</i>";
echo "<p>";
echo $linha['texto'];
$id = $linha['id_noticia'];
if (isset($_SESSION['admin'])) {
?>
<div class="noticiasOpcao">
<a href="" onClick="open_win_editar()">Editar</a>
<a onclick="return confirm('Are you sure?')" href="noticiaApagar.php?id_noticia=<?php echo $id ?>">Apagar</a>
</div>
<?php
}
}
?>
<script language="javascript">
function open_win_editar() {
window.open (
"noticiaEditarForm.php?id_noticia=<?php echo $id; ?>",
"Editar notícia",
"location=1, status=1, scrollbars=1, width=800, height=455"
);
}
</script>
<?php mysql_close($conn); ?>
</div>
My point is to then use another query to get the title and text of the article to display on an WYSIWYG editor.
Can anyone point out my flaw?