Im unten stehenden Script bekomme ich keine Datenbank-Verbindung beim UPDATE über die Funktion 'set_score'..
Der erste Aufruf von '__construct($table)' funktioniert, sowohl beim SELECT als auch im INSERT.
Allerdings erhalte ich beim 'set_score' die Meldung
" DB-Fehler: 1045 : Access denied for user...".
Für Tipps wäre ich sehr dankbar.
Udo
<?php
class rating{
public $average = 0;
public $votes;
public $gesrating = 0;
public $status;
public $table;
function __construct($table)
{
include("rating/connect/rating.open.inc.php");
$conn = @new mysqli($server, $user, $pass, $dbase);
if (mysqli_connect_errno() == 0)
{
$sql = "SELECT * FROM sterne where bericht = '$table'";
$ergebnis = $conn->query( $sql );
while ( $zeile = $ergebnis->fetch_object() )
{
$this->id = $zeile->id;
$this->votes = $zeile->anzahl;
$this->ipbereich = $zeile->ip;
$this->gesrating = $zeile->gesrating;
$this->average = $zeile->average;
$this->table = $zeile->bericht;
}
}
else
{
echo 'DB-Fehler: <span>' .mysqli_connect_errno(). ' : ' .mysqli_connect_error(). '</span>';
}
if ($this->id == "" $this->id == 0)
{
$sqln = "INSERT INTO `sterne` (`bericht`, `anzahl`, `rating`, `gesrating`, `average`, `ip`) VALUES ('$table', 0, 0, 0, 0, 'auto');";
$ergebnis = $conn->query( $sqln );
}
$conn->close();
}
function set_score($score, $ip)
{
$rown = "SELECT ip FROM sterne where bericht = $this->table";
$ergebnis = $conn->query( $rown );
while ( $zeile = $ergebnis->fetch_object() )
{
$this->ip = $zeile->ip;
}
$iparray = explode("#", $this->ip);
if (!(in_array($ip, $iparray)))
{
$average = round(( ($this->gesrating + $score) * 20 / ($this->votes + 1) ), 0);
$sqlu = "UPDATE sterne SET anzahl = anzahl + 1, ip = CONCAT(ip, '#', '$ip'), rating = '$score', gesrating = gesrating + '$score', average = '$average' WHERE bericht = $this->table";
$ergebnis = $conn->query( $sqlu );
$this->votes++;
$this->average = $average;
$this->status = '<span style=\'color:#00ff00; float:right;\'>Danke! </span>';
}
else
{
$this->status = '<span style=\'color:#00ff00\'>ist schon bewertet</span>';
}
}
}
function rating_form($table)
{
$ip = $_SERVER['REMOTE_ADDR'];
if(!isset($table) && isset($_GET['table']))
{
$table = $_GET['table'];
}
$rating = new rating($table);
$status = "<p class='score'>
<a onmouseover='Tip(\"schlecht\", ABOVE, true, BGCOLOR, \"#0000ff\", FONTSIZE, \"8pt\", FONTCOLOR, \"#ffffff\", FONTWEIGHT, \"bold\", OPACITY, 94, FADEOUT, 0, PADDING, 5, BORDERWIDTH, 0)' onmouseout='UnTip()' class='score1' href='?score=1&table=$table&user=$ip'>1</a>
<a onmouseover='Tip(\"bescheiden\", ABOVE, true, BGCOLOR, \"#0000ff\", FONTSIZE, \"8pt\", FONTCOLOR, \"#ffffff\", FONTWEIGHT, \"bold\", OPACITY, 94, FADEOUT, 0, PADDING, 5, BORDERWIDTH, 0)' onmouseout='UnTip()' class='score2' href='?score=2&table=$table&user=$ip'>2</a>
<a onmouseover='Tip(\"geht so\", ABOVE, true, BGCOLOR, \"#0000ff\", FONTSIZE, \"8pt\", FONTCOLOR, \"#ffffff\", FONTWEIGHT, \"bold\", OPACITY, 94, FADEOUT, 0, PADDING, 5, BORDERWIDTH, 0)' onmouseout='UnTip()' class='score3' href='?score=3&table=$table&user=$ip'>3</a>
<a onmouseover='Tip(\"gut\", ABOVE, true, BGCOLOR, \"#0000ff\", FONTSIZE, \"8pt\", FONTCOLOR, \"#ffffff\", FONTWEIGHT, \"bold\", OPACITY, 94, FADEOUT, 0, PADDING, 5, BORDERWIDTH, 0)' onmouseout='UnTip()' class='score4' href='?score=4&table=$table&user=$ip'>4</a>
<a onmouseover='Tip(\"klasse\", ABOVE, true, BGCOLOR, \"#0000ff\", FONTSIZE, \"8pt\", FONTCOLOR, \"#ffffff\", FONTWEIGHT, \"bold\", OPACITY, 94, FADEOUT, 0, PADDING, 5, BORDERWIDTH, 0)' onmouseout='UnTip()' class='score5' href='?score=5&table=$table&user=$ip'>5</a>
</p>
";
if(isset($_GET['score']))
{
$score = $_GET['score'];
if(is_numeric($score) && $score <=5 && $score >=1 && ($table==$_GET['table']) && isset($_GET['user']) && $ip==$_GET['user'])
{
$rating->set_score($score, $ip);
$status = $rating->status;
}
}
if(!isset($_GET['update'])){ echo "<div class='rating_wrapper'>"; }
?>
<div class="sp_rating">
<div class="rating"></div>
<div class="status">
<?php echo $status; ?>
</div>
<div class="base">
<div class="average" style="width:<?php echo $rating->average; ?>%">
<?php echo $rating->average; ?>
</div>
</div>
<div class="votes">(<?php echo $rating->votes; ?>)</div>
</div>
<?php
if(!isset($_GET['update'])){ echo "</div>"; }
}
if(isset($_GET['update'])&&isset($_GET['table']))
{
rating_form($_GET['table']);
}
?>