Salve sono nuovo del forum ed avrei un problema che mi spacca la testa da giorni...
Ho un codice che mi permette di inserire in un database dei dati, premendo il tasto submit effetto l'operazione INSERT e concludo con un header('Location: ?news) che mi aggiorna la pagina mostrandomi tutte le news attraverso una SELECT.
Il codice funziona per 8 record e poi non mostra più le notizie appena inserite (SEBBENE VENGANO INSERITE).
Per vederle devo effettuare sul click sul link della pagina stessa in quel modo vedo tutte le notizie....AIUTO!
CODICE PER RECUPERARE LE NEWS
	
	
	
		
CODICE PER INSERIRE NEWS
	
	
	
		
FILE PER VISUALIZZARE LE NOTIZIE
	
	
	
		
				
			Ho un codice che mi permette di inserire in un database dei dati, premendo il tasto submit effetto l'operazione INSERT e concludo con un header('Location: ?news) che mi aggiorna la pagina mostrandomi tutte le news attraverso una SELECT.
Il codice funziona per 8 record e poi non mostra più le notizie appena inserite (SEBBENE VENGANO INSERITE).
Per vederle devo effettuare sul click sul link della pagina stessa in quel modo vedo tutte le notizie....AIUTO!
CODICE PER RECUPERARE LE NEWS
		PHP:
	
	<?php
include_once '../../includes/magicquotes.inc.php';
if(isset($_GET['news'])) {
include_once '../includes/db.inc.php';
try
 {
    $listQuery = $pdo->prepare("SELECT  id, newsTitle, newsText, newsDate FROM news");
   $listQuery->execute();
  }
  catch (PDOException $e)
  {
    $error = 'Error searching for news.';
    include '../includes/error.html.php';
    exit();
  }
  
foreach ($listQuery as $listRow){
$newsList[] = array(
'id'=> $listRow['id'],
'newsTitle' => $listRow['newsTitle'],
'newsText' => $listRow['newsText'],
'newsDate' => $listRow['newsDate']);
	}
include 'newsList.inc.php';
}
if(isset($_POST['action']) and $_POST['action'] == 'Elimina') {
include_once '../includes/db.inc.php';
try
 {catch(PDOException $e)
{
$error = 'Error deleting news.';
    include '../includes/error.html.php';
    exit();
}
header('Location: ?news'); 
}
	CODICE PER INSERIRE NEWS
		PHP:
	
	if(isset($_POST['action']) and $_POST['action'] == 'Inserisci') {
	include_once '../includes/db.inc.php';
try
 {
$insertSQL = $pdo->prepare("INSERT INTO news SET 
newsTitle = :newsTitle, 
newsText = :newsText");
$insertSQL->bindValue(':newsTitle', $_POST['newsTitle']);
$insertSQL->bindValue(':newsText', $_POST['newsText']);
$insertSQL->execute();
}
catch(PDOException $e)
{
$error = 'Error adding news.';
    include '../includes/error.html.php';
    exit();
}
header('Location: ?news'); 
}
	FILE PER VISUALIZZARE LE NOTIZIE
		PHP:
	
	 <?php 
    session_start();
  require_once '../includes/access.inc.php';
  require_once '../includes/helpers.inc.php';
if(!isset($_SESSION['loggedIn'])) {
	header('Location: ../');
}
?>  
<div id="news">
<center><h3>Elenco notizie:</h3></center>
<div id="addNews" onclick="addNews()">  <h4>Aggiungi una nuova notizia...</h4>    </div>
<div id="insertNews">
 <form action="" method="post" > 
<table>
<tbody>
<tr><td><label for="newsTitle">Titolo:</label></td>
<td><input type="text" name="newsTitle" maxlength="255"></td></tr>
<tr>
<td>
<label for="newsText">Scrivi la notizia:</label> </td>
<td><textarea type="text" cols="40" rows="3" name="newsText"> </textarea></td>
</tr>
<tr><td>
<input type="hidden" name="action" value="upload">
<input type="submit" id="submit" name="action" class="option" value="Inserisci"></td>
<td><div class="option" onclick="addNews()">Annulla</div></td></tr>
</tbody>
</table>
</form>
</div>
<?php
session_start(); 
require_once '../includes/helpers.inc.php'; 
 require_once '../includes/access.inc.php';?>
<?php foreach($newsList as $newEl):
?>
<div class="newsCont">
<form action="" method="post" >
<div class="newsDate"><?php htmlout(date('d/m/Y', strtotime($newEl['newsDate'])));?></div>  
<div class="newsTi"> <?php htmlout($newEl['newsTitle']); ?></div>
<div class="newsTX"> <?php htmlout($newEl['newsText']); ?></div>
</div>
<input type="hidden" name="id" value= "<?php htmlout($newEl['id']); ?>">
<input type="submit"  name="action" class="elimina" value="Elimina">
</form>
<?php endforeach;?>
</div>
	
			
				Ultima modifica di un moderatore: