PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old July 11th, 2003, 01:13 AM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Question Help with php

Hey , nice site, ive learned a lot soo far buy im stuck right now. I want to make this clan member thing so that i can upload a picture for them ... ive gotten this far but i dont know how to make it so that each time i do the clan members i can put a different pic for all.

roster.php file

PHP Code:
<html>
<
body>
<?
if(
$action == "edit" && isset($HTTP_POST_VARS['password'])) {
    
//obviously you should change this password on the next line
    
if($HTTP_POST_VARS['password'] == "editpass") {
        
//First let's recompile that line with the pipe symbols so we can reinsert it
        
$line $HTTP_POST_VARS['date'] . "|" $HTTP_POST_VARS['name'];
        
$line .= "|" $HTTP_POST_VARS['age'];
    
$line .= "|" $HTTP_POST_VARS['yp'];
    
$line .= "|" $HTTP_POST_VARS['map'];
        
$line str_replace("\r\n","<BR>",$line);
        
$line .= "\r\n";
        
$data file('../cgi-bin/news/news.txt');
        
$data[$id] = $line;
        
//the next line makes sure the $data array starts at the beginning
        
reset($data);
        
//now we open the file with mode 'w' which truncates the file
        
$fp fopen('../cgi-bin/news/news.txt','w');
        foreach(
$data as $element) {
            
fwrite($fp$element);
        }
        
fclose($fp);
        echo 
"Item Edited!<BR><BR>\n";
        echo 
"<a href=\"$PHP_SELF\">Go Back</a>\n";
        exit;
    } else {
        echo 
"Bad password!\n";
        exit;
    }
}
if(
$action == "edit") {
    
$data file('../cgi-bin/news/news.txt');
    
$element trim($data[$id]);
    
$pieces explode("|"$element);
    
//the next line is to reverse the process of turning the end of lines into breaking returns
    
$news str_replace("<BR>","\r\n",$pieces[2]);
    echo 
"Make the changes you would like and press save.<BR>\n";
    echo 
"<FORM ACTION=\"$PHP_SELF?action=edit\" METHOD=\"POST\" NAME=\"editform\">\n";
    echo 
"Name:<BR>\n";
    echo 
"<INPUT TYPE=\"text\" SIZE=\"30\" NAME=\"name\" value=\"".$pieces[1]."\"><BR>\n";
    echo 
"Age:<BR>\n";
    echo 
"<INPUT TYPE=\"text\" SIZE=\"30\" NAME=\"age\" value=\"".$pieces[2]."\"><BR>\n";
    echo 
"Years Playing:<BR>\n";
    echo 
"<INPUT TYPE=\"text\" SIZE=\"30\" NAME=\"yp\" value=\"".$pieces[3]."\"><BR>\n";
    echo 
"Favorite Map:<BR>\n";
    echo 
"<INPUT TYPE=\"text\" SIZE=\"30\" NAME=\"map\" value=\"".$pieces[4]."\"><BR>\n";
    echo 
"Password:<BR>\n";
    echo 
"<INPUT TYPE=\"password\" SIZE=\"30\" NAME=\"password\"><BR>\n";
    echo 
"<INPUT TYPE=\"hidden\" NAME=\"date\" VALUE=\"".$pieces[0]."\">\n";
    echo 
"<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$id\">\n";
    echo 
"<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Save\"><BR>\n";
    echo 
"</FORM>\n";
    exit;
}
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('../cgi-bin/news/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('../cgi-bin/news/news.txt','w');
        foreach(
$data as $element) {
            
fwrite($fp$element);
        }
        
fclose($fp);   
        echo 
"Item deleted!<BR><BR>\n";   
        echo 
"<a href=\"$PHP_SELF\">Go Back</a>\n";
        exit;
    } else {
        echo 
"Bad password!\n";
        exit;
    }
}
if(
$action == "delete") {
    echo 
"<H2>You are about to delete the following news item.</H2>\n";
    
$data file('../cgi-bin/news/news.txt');
    
$element trim($data[$id]);
    
$pieces explode("|"$element);
    echo 
$pieces[1] . "<BR>" $pieces[2] . "<BR>" $pieces[3] . "<BR>" $pieces[4]. "</b>\n";
    echo 
"<BR><BR>\n";
    echo 
"Are you sure you want to delete this news item? If so, enter the password and click on Delete.<BR>\n";
    echo 
"<FORM ACTION=\"$PHP_SELF?action=delete\" METHOD=\"POST\" NAME=\"deleteform\">\n";
    echo 
"Password:<BR>\n";
    echo 
"<INPUT TYPE=\"password\" SIZE=\"30\" NAME=\"password\"><BR>\n";
    echo 
"<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$id\">\n";
    echo 
"<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Delete\"><BR>\n";
    echo 
"</FORM>\n";
    exit;
}
echo 
"<H1><u>Current Roster</u></H1>\n";
$data file('../cgi-bin/news/news.txt');
//next line removed to make everything else easier in the admin script
//$data = array_reverse($data);
foreach($data as $key=>$element) {
    
$element trim($element);
    
$pieces explode("|"$element);
    echo 
"<center><table cellspacing=0 cellpadding=0 cellwall=o border=0><tr><td><img src=template/name.gif></td><td 

width=200>" 
$pieces[1] . "</td></tr><tr><td td bgcolor=#E2E2E2><img src=template/age.gif></td><td bgcolor=#E2E2E2 

width=200>" 
$pieces[2] . "</td></tr><tr><td><img src=template/yp.gif></td><td width=200 >" $pieces[3] . 

"</td></tr><tr><td bgcolor=#E2E2E2><img src=template/map.gif></td><td bgcolor=#E2E2E2 width=200>" $pieces[4] . 

"</td></tr></table>" "</b>\n";
    echo 
"<br> <a href=\"$PHP_SELF?action=delete&id=$key\">Delete</a>\n";
    echo 
"<a href=\"$PHP_SELF?action=edit&id=$key\">Edit</a>\n";
    echo 
"<BR><BR>\n";
}
?>
</body>
</htmL> 


addmem.php file

PHP Code:
<html>
<
body>
<?
//this should all go into one file. I would name it addnews.php

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['age']) {
            echo 
"You must enter an age";
            exit;
        }
        if(
strstr($HTTP_POST_VARS['name'],"|")) {
            echo 
"Name cannot contain the pipe symbol - |";
            exit;
        }
        if(
strstr($HTTP_POST_VARS['yp'],"|")) {
            echo 
"News cannot contain the pipe symbol - |";
            exit;
    }
        if(
strstr($HTTP_POST_VARS['age'],"|")) {
            echo 
"News cannot contain the pipe symbol - |";
            exit;
        }
        
$fp fopen('../cgi-bin/news/news.txt','a');
        if(!
$fp) {
            echo 
"Error opening file!";
            exit;
        }
        
$line date("m.d.y") . "|" $HTTP_POST_VARS['name'];
        
$line .= "|" $HTTP_POST_VARS['age'];
    
$line .= "|" $HTTP_POST_VARS['yp'];
    
$line .= "|" $HTTP_POST_VARS['map'];
        
$line str_replace("\r\n","<BR>",$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">
Name:<BR>
<INPUT TYPE="text" SIZE="30" NAME="name"><BR>
Age:<BR>
<INPUT TYPE="text" SIZE="30" NAME="age"><BR>
Years Playing?:<BR>
<INPUT TYPE="text" SIZE="30" NAME="yp"><br>
Favorite Map:<BR>
<INPUT TYPE="text" SIZE="30" NAME="map"><BR><BR>
News Password:<BR>
<INPUT TYPE="password" SIZE="30" NAME="password"><BR>
<INPUT TYPE="submit" NAME="submit" VALUE="Post it!"><BR>
</FORM>
</body>
</htmL> 


thanks to Matt Wade for getting me started on this.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Help with php


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway