Hallo,könnte mir bitte jemand weiterhelfen? hab vor n paar tagen ein Newsscript tutorial gefunden das meinen wünschen entsprechen würde...nur komm ich einfach nicht mehr weiter....Ich hoffe jemand von euch kann mir auf die sprünge helfen.
1. Addnews.php
2. news.txt (auf Chmod777 eingestellt)
3. News.php (zum anzeigen der news.txt Datei)
4. Admin.php (Die Datei wo ich nicht mehr weiter weis

)
1.Addnews.php PHP-Code:
<?php
<?
//this should all go into one file. I would name it addnews.php
if($HTTP_POST_VARS['submit']) {
if($HTTP_POST_VARS['password'] == 'pass') {
if(!$HTTP_POST_VARS['name']) {
echo "You must enter a name";
exit;
}
if(!$HTTP_POST_VARS['news']) {
echo "You must enter some news";
exit;
}
if(strstr($HTTP_POST_VARS['name'],"|")) {
echo "Name cannot contain the pipe symbol - |";
exit;
}
if(strstr($HTTP_POST_VARS['news'],"|")) {
echo "News cannot contain the pipe symbol - |";
exit;
}
$fp = fopen('news.txt','a');
if(!$fp) {
echo "Error opening file!";
exit;
}
$line = date("m.d.y") . "|" . $HTTP_POST_VARS['name'];
$line .= "|" . $HTTP_POST_VARS['news'];
$line = str_replace("\r\n","
",$line);
$line .= "\r\n";
fwrite($fp, $line);
if(!fclose($fp)) {
echo "Error closing file!";
exit;
}
} else {
echo "Bad Password";
}
}
?>
<FORM ACTION="<?=$PHP_SELF?>" METHOD="POST" NAME="newsentry">
Your name:
<INPUT TYPE="text" SIZE="30" NAME="name">
The News:
<TEXTAREA NAME="news" COLS="40" ROWS="5"></TEXTAREA>
News Password:
<INPUT TYPE="password" SIZE="30" NAME="password">
<INPUT TYPE="submit" NAME="submit" VALUE="Post it!">
</FORM>
?>
2.Admin.php(wo ich nicht weiter weis) PHP-Code:
<?php
<?
echo "<H1><u>Current News</u></H1>\n";
$data = file('news.txt');
$data = array_reverse($data);
foreach($data as $element) {
$element = trim($element);
$pieces = explode("|", $element);
echo $pieces[2] . "
" . "[b]Posted by " . $pieces[1] . " on " . $pieces[0] . "[/b]
";
}
echo "<HR>\n";
echo "<H1><u>Add News</u></H1>\n";
if($HTTP_POST_VARS['submit']) {
if($HTTP_POST_VARS['password'] == 'pass') {
if(!$HTTP_POST_VARS['name']) {
echo "You must enter a name";
exit;
}
if(!$HTTP_POST_VARS['news']) {
echo "You must enter some news";
exit;
}
if(strstr($HTTP_POST_VARS['name'],"|")) {
echo "Name cannot contain the pipe symbol - |";
exit;
}
if(strstr($HTTP_POST_VARS['news'],"|")) {
echo "News cannot contain the pipe symbol - |";
exit;
}
$fp = fopen('news.txt','a');
if(!$fp) {
echo "Error opening file!";
exit;
}
$line = date("m.d.y") . "|" . $HTTP_POST_VARS['name'];
$line .= "|" . $HTTP_POST_VARS['news'];
$line = str_replace("\r\n","
",$line);
$line .= "\r\n";
fwrite($fp, $line);
if(!fclose($fp)) {
echo "Error closing file!";
exit;
}
echo "[b]News added![/b]\n";
} else {
echo "Bad Password";
}
}
?>
<FORM ACTION="<?=$PHP_SELF?>" METHOD="POST" NAME="newsentry">
Your name:
<INPUT TYPE="text" SIZE="30" NAME="name">
The News:
<TEXTAREA NAME="news" COLS="40" ROWS="5"></TEXTAREA>
News Password:
<INPUT TYPE="password" SIZE="30" NAME="password">
<INPUT TYPE="submit" NAME="submit" VALUE="Post it!">
</FORM>
?>
(Soweit bin ich gekommen doch nun
keinen plan wo das hingehört um den link zu aktivieren der die news löscht..... Tutorial
Ok, let's make the links actually do something! Let's deal with the delete link first. It is a bit less complicated than the edit link. First thing we will need to do is add a line of code that checks to see if the delete link has been clicked. We will check to see if the $action variable is set to delete with some code like this.
PHP-Code:
<?php
<?php
if($action == "delete") {
?>
?>
Simple enough eh? Ok, now we need to check a password to make sure it is ok to delete it and at the same time we will be confirming the deletion. We are basically going to do the same thing as we would to display all the news, except we are going to use the id we passed to the delete portion of the script to only display the one news item we want to delete.
PHP-Code:
<?php
<?php
if($action == "delete") {
echo "<H2>You are about to delete the following news item.</H2>\n";
$data = file('news.txt');
$element = trim($data[$id]);
$pieces = explode("|", $element);
echo $pieces[2] . "
" . "[b]Posted by " . $pieces[1] . " on " . $pieces[0] . "[/b]\n";
echo "
\n";
echo "Are you sure you want to delete this news item? If so, enter the password and click on Delete.
\n";
echo "<FORM ACTION=\"$PHP_SELF?action=delete\" METHOD=\"POST\" NAME=\"deleteform\">\n";
echo "Password:
\n";
echo "<INPUT TYPE=\"password\" SIZE=\"30\" NAME=\"password\">
\n";
echo "<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$id\">\n";
echo "<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Delete\">
\n";
echo "</FORM>\n";
exit;
}
?>
?>
You'll notice that I included a hidden field that holds the id that was passed to the delete portion of the script. The reason I did this is that we will still need this id when we actually delete the news item. Now, what we need to do is add some code that checks to see if the action is set to delete AND the password field of the form has been set.
PHP-Code:
<?php
<?php
if($action == "delete" && isset($HTTP_POST_VARS['password'])) {
?>
?>
Ok, that should suffice. That line should go to the very top of our script. Definitely make it above the last snippet that checked for an action of delete. If we don't check this first, things won't execute in the order we want them to. Now, let's check the password and then actually delete the news item.
PHP-Code:
<?php
<?php
if($action == "delete" && isset($HTTP_POST_VARS['password'])) {
//obviously you should change this password on the next line
if($HTTP_POST_VARS['password'] == "deletepass") {
$data = file('news.txt');
//this next line will remove the single news item from the array
array_splice($data,$id,1);
//now we open the file with mode 'w' which truncates the file
$fp = fopen('news.txt','w');
foreach($data as $element) {
fwrite($fp, $element);
}
fclose($fp);
echo "Item deleted!
\n";
echo "<a href=\"$PHP_SELF\">Go Back</a>\n";
exit;
} else {
echo "Bad password!\n";
exit;
}
}
?>
?>
Könnt ihr mir bitte weiterhelfen ich hab keine ahnung mehr wo ich den code hinschreiben soll.....Mfg.SilentNoice