Hallo ich hab mal ein kleines nachrichten script gebastelt ist aber noch nicht ganz so wie ich es haben möchte deshalb stell ichs erstmal hierrein!
nachrichten.php
nachrichtloschen.php
nachrichtsenden.php
antworten.php
die datenbank war
CREATE TABLE game_nachrichten (
Id INT AUTO_INCREMENT PRIMARY KEY,
Title VARCHAR(100),
Text TEXT,
Datum DATETIME,
Name VARCHAR(50),
Absender VARCHAR(50)
);
geschrieben hab ich das schon letzten monat da hats auch gefunst ich hoffe ich hab nichts vergessen!
Kritik sind erwünscht
grüße
nachrichten.php
PHP:
<?php
include ("../dblogin.php");
$sql = "SELECT
Id, Text, Title, Datum, Name
FROM
game_nachrichten WHERE Name = '".$_COOKIE["nutzer"]."' ORDER BY Datum ASC LIMIT 10
";
$adressen_query1 = mysql_query($sql) or die("Anfrage nicht erfolgreich"); // hier mach ich noch 1 abfrage raus nicht 3 wusste am anfang noch nciht das man nur 1 braucht!
$adressen_query2 = mysql_query($sql) or die("Anfrage nicht erfolgreich");
$adressen_query10 = mysql_query($sql) or die("Anfrage nicht erfolgreich");
$anzahlnachrichten10 = mysql_num_rows($adressen_query10);
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<div id="haupt">
<p align="center"><big>.:: Nachrichten ::.</big></p>
<?php
if ($anzahlnachrichten10 == "10"){
echo "<font color=\"#CC0000\">Sie müssen erst Nachrichten löschen um neue zu empfangen!<br>ACHTUNG!! Wenn sie alle Nachrichten löschen werden die neuen Nachrichten die sie durch die begrenzung noch nicht lesen konnten auch gelöscht!</font>";
}
?>
<form name="form1" method="POST" action="antworten.php">
<select name="nachricht[]" size="10" style="width: 100%;">
<?php
while ($adr = mysql_fetch_array($adressen_query1)){
?>
<option><?=$adr['Title']?></option>
<?php
} //while
?>
</select><br>
<input type="submit" value="Lesen/Antworten"><br>
</form>
<?php
if (isset ($_REQUEST["fehler"]))
{
echo "Fehler beim Löschen!<br>";
}
if (isset ($_REQUEST["fehlersenden"]))
{
echo "Fehler beim Senden!<br>";
}
?>
<form action="nachrichtenloschen.php" method="POST">
<select name="nachrichtloschen[]" size="1">
<option>- - - - - - - - - - - - - - - - - - - - - -</option>
<option>Alle</option>
<option>- - - - - - - - - - - - - - - - - - - - - -</option>
<?php
while ($adr = mysql_fetch_array($adressen_query2)){
?>
<option><?=$adr['Title']?></option>
<?php
} //while
?>
</select>
<input type="submit" value="Löschen">
</form>
<p align="center"><big>.:: Nachricht schreiben ::.</big></p>
<form action="nachrichtsenden.php" method="POST">
<input type="text" value="Name des Spielers" name="Spieler" maxlength="20"><br>
<input type="text" value="Titel" name="Titel" maxlength="60">
<TEXTAREA type="TextBox" name="NText" rows="10" style="width: 100%;"></TEXTAREA><br>
<input type="submit" value="Senden">
</form>
</div>
</body>
</html>
nachrichtloschen.php
PHP:
<?php
$loschen = $_POST["nachrichtloschen"];
include ("../dblogin.php");
for($i=0; $i<1; $i++){
if ($loschen[$i] == "- - - - - - - - - - - - - - - - - - - - - -"){
header ("Location: nachrichten.php");
}
if ($loschen[$i] == "Alle"){
$sql = "DELETE FROM game_nachrichten WHERE Name = '".$_COOKIE["nutzer"]."'";
mysql_query ($sql);
if (mysql_affected_rows ($connectionid) > 0){
header ("Location: nachrichten.php");
}
else{
header ("Location: nachrichten.php?fehler=1");
}
}
else{
$sql = "DELETE FROM game_nachrichten WHERE Title = '$loschen[$i]' "."&&"." Name = '$nutzer'";
mysql_query ($sql);
if (mysql_affected_rows ($connectionid) > 0){
header ("Location: nachrichten.php");
}
else{
header ("Location: nachrichten.php?fehler=1");
}
} // else
} //for
?>
nachrichtsenden.php
PHP:
<?php
include ("../dblogin.php");
$sql = "INSERT INTO ".
"game_nachrichten (Name, Absender, Title, Text, Datum) ".
"VALUES ('".$_REQUEST["Spieler"]."','".$_COOKIE["nutzer"]."','".
$_REQUEST["Titel"]."','".
$_REQUEST["NText"]."', NOW())";
mysql_query ($sql);
if (mysql_affected_rows ($connectionid) > 0){
header ("Location: nachrichten.php");
}
else{
header ("Location: nachrichten.php?fehlersenden=1");
}
?>
antworten.php
PHP:
<?php
$gast = $_POST["nachricht"];
for($i=0; $i<1; $i++){
include ("../dblogin.php");
$sql = "SELECT Id, Text, Title, Datum, Name, Absender FROM game_nachrichten WHERE Title = '$gast[$i]'";
}
$adressen_query = mysql_query($sql) or die("Anfrage nicht erfolgreich");
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<?php include ("grund.php")?>
<div id="haupt">
<p align="center"><big>.:: Lesen ::.</big></p>
<?php
while($adr = mysql_fetch_array($adressen_query)){
?>
<form action="">
<input type="text" value="<?=$adr['Title']?>" readonly>
<input type="text" value="<?=$adr['Absender']?>" readonly>
<input type="text" value="<?=$adr['Datum']?>" readonly><br>
<TEXTAREA type="TextBox" rows="10" style="width:100%;" readonly><?=$adr['Text']?></TEXTAREA>
</form>
<p align="center"><big>.:: Antworten ::.</big></p>
<form action="nachrichtsenden.php" method="POST">
<input type="text" value="<?=$adr['Absender']?>" name="Spieler" maxlength="20"><br>
<input type="text" value="Titel" name="Titel" maxlength="60"><br>
<TEXTAREA type="TextBox" name="NText" rows="10" style="width:100%;"></TEXTAREA><br>
<input type="submit" value="Senden">
</form>
<?php
} //klammer von while
?>
</div>
</body>
</html>
die datenbank war
CREATE TABLE game_nachrichten (
Id INT AUTO_INCREMENT PRIMARY KEY,
Title VARCHAR(100),
Text TEXT,
Datum DATETIME,
Name VARCHAR(50),
Absender VARCHAR(50)
);
geschrieben hab ich das schon letzten monat da hats auch gefunst ich hoffe ich hab nichts vergessen!
Kritik sind erwünscht
grüße
Zuletzt bearbeitet: