questo script implementato in una pagina PHP
Codice PHP:
//prima di questo script sotto ci sono i codici della mia pagina web
<?php
$limit = 10; // articoli per pagina
$mysql = mysql('localhost', 'root', '', 'html_it_articles');
if($mysql)
{
die("Errore di connessione al database, impossibile procedere");
}
$result = $mysql->query("SELECT COUNT(*) AS tot FROM articles")->fetch_assoc();
$page = isset($_GET['p']) ? $_GET['p'] : 1;
$totals = $result['tot'];
$totals_pages = ceil($totals / $limit);
$articles = $mysql->query("
SELECT
AR.id AS id,
AR.title AS title,
CONCAT(SUBSTR(AR.article, 1, 200), ' ...') AS content,
CONCAT(AU.surname, ' ', AU.name) AS author
FROM
articles AR,
authors AU
WHERE
AR.author_id = AU.id
ORDER BY id DESC
LIMIT ".(($page - 1) * $limit).",".$limit);
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Articoli</title>
</head>
<body>
<ul>[*][url="News.php"]Lista articoli[/url][/list]
Articoli totali: <?php echo $totals; ?></p>
<table width="500px">
<?php
while($article = $articles->fetch_assoc())
{
printf('<tr>
<td>%d. [url="show.php?id=%d"]%s[/url] (%s) </td>
</tr>
<tr>
<td>
%s</p></td>
</tr>
<tr>
<td><hr /></td>
</tr>',
$article['id'],
$article['id'],
$article['title'],
$article['author'],
$article['content']
);
}
?>
</table>
Pagina <?php echo $page; ?> di <?php echo $totals_pages; ?>
<?php
if($page - 1 > 0)
{
echo '[url="?p='.($page - 1).'"]< prev[/url] | ';
}else
{
echo '< prev | ';
}
if($page + 1 <= $totals_pages)
{
echo '[url="?p='.($page + 1).'"]next >[/url]';
}else
{
echo 'next >';
}
?>
</p>
</body>
</html></div>
<div id="wb_Shape8" style="position:absolute;left:600px;top:153px;width:214px;height:54px;z-index:23;" align="center">
[img]images/img0064.png[/img]</div>
<div id="Html3" style="position:absolute;left:606px;top:162px;width:212px;height:51px;z-index:24">
<?php
session_start();
require('connessionedb.php'); //o le vostre istruzioni per il collegaamento al db
if(!isset($_SESSION['log']))
{
$_SESSION['log'] = 0;
}
if(!isset($_SESSION['username']))
{
$_SESSION['username'] = "Non Registrato";
}
// Ora controlliamo se $_SESSION['log']!=1, cioè se l'utente non è logato
if ($_SESSION['log'] != 1)
{
// Se non lo è procediamo come segue:
if(isset($_POST['pass']) && isset($_POST['user']))
{
$qry_pass = mysql_real_escape_string(md5($_POST['pass']));
$qry_user = mysql_real_escape_string($_POST['user']);
/*Da notare l'utilizzo di md5 per trasformare di nuovo il valore della
password passata nel suo hash per poterla confrontare con quella contenuta nel db.
Poi procediamo verificando username, password e stato registrazione */
$query = "SELECT * " .
"FROM user " .
"WHERE user_username = '$qry_user' " .
"AND user_password = '$qry_pass' " .
"AND user_reg = 1 ";
$results = mysql_query($query) or die (mysql_error());
if(mysql_num_rows($results) != 0)
{
$row = mysql_fetch_array($results);
$_SESSION['log'] = 1; // utente logato
$_SESSION['username'] = $row['user_username'];
}
}
}
echo "Utente on-line: [b]" . $_SESSION['username'] . "[/b]
";
?> </div>
</div>
</body>
</html>
mi da questo errore
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /membri/sk1zzo/News.php on line 190
e la riga 190 è questa
Codice PHP:
$result = $mysql->query("SELECT COUNT(*) AS tot FROM articles")->fetch_assoc();