School Map:  Home / Enroll $ Student Records; Class  
$ News @ LIVE Tech Radio * Support/FAQ | Store | FORUMS

Class / Forums / php101 Refresh the current page Week #10 ADVANCED To-Do Assignment, post here
 

 (#19 2003-08-07 16:57:50) Post Reply

TDavid
php mySQL Perl C/C++
Principal


Enrolled: Mar 2000
Posts: 193
AP: 1

Week #10 ADVANCED TO-DO ASSIGNMENT: Write a script to be able to add and delete sorted email addresses and names to a file and with the same script how to retrieve all the information and print to browser the name and email address in a table to the browser.

Post this assignment here so that we can offer comment/critique for you, but also post a URL to the working copy of the script and the complete source code of the script in your post.

scriptname.php <-- script name

Good luck to you!

 

 (#267 2003-09-22 08:17:13) Post Reply

Shrek
Need To Set


Enrolled: Aug 2003
Posts: 33
AP: 1

My Week 10 Advanced Assignment http://members.lycos.co.uk/jef...an/class10a.php



<?
$error
= 'Sorry, I could not open this file! Check that the permissions are set properly for this file and that you used the correct absolute path to the file.';
$file_contents = file('filemail');
sort($file_contents);
$sizeof = count($file_contents);

$action=$_REQUEST['action'];
$todelete=$_REQUEST['todelete'];
$user=$_REQUEST['user'];
$email=$_REQUEST['email'];

switch (
$action)
{
case
'add':
echo (
"Enter add Mode<br>");
if(
$filehandle = fopen("filemail", "a"))
{
fputs($filehandle, "$user:$email\n");
fclose($filehandle);
print(
"Successfully added <b>$user</b> to the file<br>");
} else {
echo(
$error);
}
echo (
"Click <a href=".$_SERVER['PHP_SELF'].">Here</a> to Refresh!<br>");
exit;
break;
case
'delete':
echo (
"Enter Delete Mode<br>");
if(
$filehandle = fopen("filemail", "w"))
{
for(
$i=0; $i < $sizeof; $i++)
{
if(
$file_contents[$i] != $todelete."\n")
{
fputs($filehandle, "$file_contents[$i]");
} else
{
$flag = 1;
}
}
fclose($filehandle);
if(
$flag)
{
print(
"Successfully deleted <b>$todelete</b> from the file<br>");
} else
{
print(
"I didn't find $todelete to delete from file");
}
} else
{
echo(
$error);
}
echo (
"Click <a href=".$_SERVER['PHP_SELF']."> Here to Refresh!<br>");
exit;
break;
default:
?>
<table summary="OutPut Name">
<tr>
<td>Name</td>
<td>Email</td>
<td>Option</td>
</tr>
<?
for($i=0; $i < $sizeof; $i++)
{
echo (
"<tr>");
$user = explode(":", $file_contents[$i]);
echo (
"<td>".$user[0]."</td>");
echo (
"<td><a href='mailto:".$user[1]."'>".$user[1]."</a></td>");
echo (
"<td><a href='".$_SERVER['PHP_SELF']."?action=delete&todelete=".$file_contents[$i]."'>Delete</a>");
echo (
"</tr>");
}
?>
</table>
<form method=POST action=<? echo ($_SERVER['PHP_SELF']); ?> >
<input type="hidden" name="action" value="add">
Username: <br>
<input type="text" name="user" size=10><br>
Email Address: <br>
<input type="text" name="email" size=10><br>
<input type="submit" value="Add New User">
</form>
<?
exit;
break;
}
?>



 

 (#370 2003-11-06 06:06:51) Post Reply

Dest
Need To Set


Enrolled: Oct 2003
Posts: 18
AP: 1

here is my assignment. I will not give you admin password because i want to see who will add himself :)

url - http://tts.lt/~sir/scripts/week10adv.php




<?
// setting variables
$fdirectory="files";
$fcontents=file("$fdirectory/week10adv.htp");
$sizeof=count($fcontents);
$error="Error. Cant read file";
sort($fcontents);
$realpass="************";

//If we don't want to add or delete nothing do following:
if(($action!="add") or ($action!="delete")) { ?>

<html>
<title> Week 10 advanced to-do assignment </title>
<body>

<table border="0" bordercolor="#111111" width="100%" >
<tr>
<td width="25%" valign=top><center><form method=POST action=<?print($PHP_SELF);?> >
Add new user:<br><br><input type=hidden name=action value=add>
Name:<input type=text name=name size=15><br>
E-mail:<input type=text name=mail size=15><br>
<input type=submit value="Add user"></form><form method=POST action=<?print("$PHP_SELF");?> ><input type=submit value=Refresh></form>
<font size=2><b><font color=red>Note:</b></font> Don't forget to press Refresh button after adding new user.</center>
<?
//if add form done, add name to the file.
}

if(
$action=="add") {
if(
$filehandle=fopen("$fdirectory/week10adv.htp", "a")) {
fputs($filehandle, "$name:$mail\n");
fclose($filehandle);
print(
"<center>Successfully added $name to the file<center>"); }
else {
print(
$error); }
}
?>
</td>

<td width="50%" valign=top><font size=4><center> Our users (name: email):<br><br> </font>

<?
//print users into browser using loop
for($f=0; $f<$sizeof; $f++) { $mailname=explode(":", $fcontents[$f]); print("
<font size=3>$mailname
[0]:&nbsp;&nbsp;&nbsp;<a href=mailto:$mailname[1]>$mailname[1]</a><br></font>"); } ?></center></td>

<td width="25%" valign=top><center><form method=POST action=<?print($PHP_SELF);?> >
Delete user:<br><br>
<input type=hidden name=action value=delete>
User to delete:<select name=todelete>
<? for($i=0; $i<$sizeof; $i++) {
$user=explode(":", $fcontents[$i]);
print(
"<option value=\"$fcontents[$i]\">$user[0]</option>"); }
?> </select> <br>
Deletion password:<input type=password name=pass size=15><br><input type=submit value="Delete user"> </form><form method=POST action=<?print("$PHP_SELF");?> ><input type=submit value=Refresh></form>
<font size=2> <b><font color=red>Note:</b></font> Delete users can only people who knows deletion password.</center>

<?
//if delete form is done and admin password is correct, delete user. if pass is not correct, give a warning.
if($action=="delete"&&$pass=="$realpass") {
if(
$filehandle=fopen("$fdirectory/week10adv.htp", "w")) {
for(
$i=0; $i<$sizeof; $i++) {
if(
$fcontents[$i]!=$todelete) {
fputs($filehandle, "$fcontents[$i]"); }
else {
$flag = 1; } }
fclose($filehandle);
if(
$flag) {
$usertodelete=explode(":", $todelete);
print(
"User $usertodelete[0] was successfully deleted from file"); }
else { print(
"Can't find $usertodelete[0] in our file"); }
}
}
elseif(
$action=="delete"&&$pass!="$realpass") {
print(
"<font color=red size=2><b>You can't delete users.</b> Password is incorrect</font>"); }
?>
</td>
</tr>
</table>
</body>
</html>



 

 (#402 2003-11-23 17:18:51) Post Reply

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

here it is


<?
global $PHP_self;
$SCRIPT_NAME = $_SERVER["SCRIPT_NAME"];
$action = $_POST["action"];
$name = $_POST["name"];
$email = $_POST["email"];
$valid = "(.+)\@(.+)\.(.+)";
$theone = $_POST["theone"];

if(
$action == "addemail") {
if(
eregi($valid, $email)) {
if(
$buffer = fopen("10.assignement", "a")) {
fputs($buffer, $name."§"."$email\r\n");
fclose($buffer); } else {
print(
"Error accessing file.");
exit(); } } else {
print(
"<font color=\"red\"><b>Error:</b> Please insert a correct email address.</font><br><br>"); } }

if(
$action == "deleteemail") {
if(
$buffer = fopen("10.assignement", "r")) {
while(!
feof($buffer)) { $file[] = fgets($buffer); }
fclose($buffer); } else {
print(
"Error accessing file."); }
sort($file);
$number = count($file);

if(
$buffer = fopen("10.assignement", "w")) {
for(
$a=1; $a<$number; $a++) {
if(
$a != $theone) {
fwrite($buffer, $file[$a]); } }
fclose($buffer);
$action = "done"; } else {
print(
"Error accessing file.");
exit(); }
header("Location: $SCRIPT_NAME"); }

if(
$buffer = fopen("10.assignement", "r")) {
while(!
feof($buffer)) { $file[] = fgets($buffer); }
fclose($buffer); } else {
print(
"Error accessing file.");
exit(); }

if(
$file[0] == "") {
print(
"<b>No stored emails.</b><br><br>"); } else {

sort($file);
$number = count($file);
print(
"<b>Stored emails</b><br><table border=1 cellspacing=0>
<tr><td align=\"center\">Name</td>
<td align=\"center\" colspan=\"2\">Email</td></tr>"
);

for(
$a=1; $a < $number; $a++) {
$toshow = explode("§", $file[$a]);
print(
"<tr><td>$toshow[0]</td>
<td><a href=
\"mailto:$toshow[1]\">$toshow[1]</a></td>
<form method=
\"post\" action=\"$PHP_self\">
<input type=
\"hidden\" name=\"action\" value=\"deleteemail\">
<input type=
\"hidden\" name=\"theone\" value=\"$a\">
<td><input type=
\"submit\" value=\"delete\"></td></form></tr>"); }

print(
"</table><br><br>"); }
?>

<table>
<form method="post" action="<? $PHP_self ?>">
<input type="hidden" name="action" value="addemail">
<tr><td>Name: </td><td><input type="text" name="name" size="50"></td></tr>
<tr><td>Email: </td><td><input type="text" name="email" size="50"></td></tr>
<tr><td aligin="left" colspan="2"><input type="submit" value="Add email"></td></tr>
</form>
</table>


working url

 

 (#764 2005-01-20 14:50:03) Post Reply

lestat
Need To Set


Enrolled: Jan 2004
Posts: 44
AP: 1

Took me a while but finally got it after looking for lots of help in the irc chat. I'm now trying to make a checkbox version.


<?
// [ DIR PATH, & CONTENTS ]
$action = $_POST['action'];
$email = $_POST['email'];
$name = $_POST['name'];
$path_to_dir = '/my/path'; // path to text file
$file_contents = file("$path_to_dir/email.txt");
$error = "Whoops, Can't read/write or access the file for some reason<br>"; // error msg
$sizeof = count($file_contents);

// [ ADD ENTRY TO FLAT FILE ]
if($_POST['action'] == "true"){
if((
$name == " " || $email == " ") || ($name == "" || $email == "")){ // Disallow blank or empty string entries
print("<b>Invalid Entry</b>, Please go back and check your entry");
}else{
if(
ereg("([[:alnum:].-]+)(@[[:alnum:].-]+.+)", $email)){ // proceed ONLY if email is valid format
if($filehandle = fopen("$path_to_dir/email.txt", "a")){ // Open the file
fputs($filehandle, "$name" . ":" . "$emailrn"); // Append the contents
print("Added,<b> $name </b>with the address<b> $email </b>to the flat file"); // Print confirm
fclose($filehandle);
}else{
echo
$error;
}
}else{
print(
"Sorry, <b>$email</b>, is not a correct email format,<br>Please go back and correct the address");
}
}
}

// [ DELETE SELECTED ]
$file_contents = file("$path_to_dir/email.txt");
sort($file_contents); // alphabetically sort contents
$sizeof = count($file_contents);
if(
$_POST['action'] == "delete"){
if(
$filehandle = fopen("$path_to_dir/email.txt", "w")){ // open file for writing
for($i = 0; $i<$sizeof; $i++){ // loop through file
if($i != $file_to_delete){ // Dont write THIS line into file if it matches (this is the one to remove/not write)
fputs($filehandle, "$file_contents[$i]"); // write the file
}else{
$flag = 1;
}
}
fclose($filehandle); // close the file
if($flag){
print(
"Deleted <b>$file_contents[$file_to_delete]</b>");
}else{
print(
"Could not find, <b>$file_contents[$file_to_delete]</b> to delete");
}
}else{
echo(
$error);
}
}


// [ READ & OUTPUT FILE CONTENTS ]
$file_contents = file("$path_to_dir/email.txt");
$sizeof = count($file_contents); // count how many lines of content are in the flat file
sort($file_contents); // alphabetically sort contents
print("<table border=1> <tr><td class="spectable"><b>Name:</b></td><td class="spectable"><b>Email:</b></td><td class="spectable"><b>Delete</b></td></tr>");
if(
$filehandle = fopen("$path_to_dir/email.txt", "r")){
while(!
feof($filehandle)){
$file_contents[] = fgets($filehandle);
}
for(
$i=0; $i<$sizeof; $i++){
$entry=explode(":", $file_contents[$i]); // Table with output and DELETE form
print ("<tr><td class="spectable">" . $entry[0] . "</td><td class="spectable">" . $entry[1] . "</td>
<td class="
spectable"><form method=POST action=$PHP_SELF style=margin:0;>
<input type=hidden name=action value=delete>
<input type=hidden name=file_to_delete value=$i>
<input type=submit value=delete>
</form></td></tr>"
);
}
print(
"</table><br>");
}else{
echo(
$error);
}
?>

<table border="0" align="left">
<form method="POST" action="<? $PHP_SELF ?>">
<input type="hidden" name="action" value="true">
<tr><td align="center">Name:<input type="text" name="name"></td></tr>
<tr><td align="center">Email:<input type="text" name="email"></td></tr>
<tr><td colspan="2"><center><input type="submit" name="submit" value="submit"></center></td></tr>
</form>
</table>


Working URL: http://tdurl.com/bs

 

 (#844 2005-07-03 05:31:39) Post Reply

vegyta2004
Need To Set


Enrolled: Apr 2005
Posts: 34
AP: 1

MY code:

<form method=POST action="<?$PHP_SELF ?>">
Username: <input type="text" name="user" size=10><br>
Password: <input type="password" name="pwd" size=10><br>
<input type="hidden"name="action"value="add">
<input type="submit" value="add user"><br>
</form>
<?
$file_directory ="D:\PROGRAME INSTALATE-FUNCTIONALE\wamp\www\proiecte\assignments\week10\basic\pass.txt";
$error = 'Sorry, I could not open this file! Check that the permissions are set properly
for this file and that you used the correct absolute path to the file.';
$file_contents = file("$file_directory");
sort($file_contents);
$sizeof = count($file_contents);
if(($_POST["action"] != "delete")||($_POST["action"] != "add")) {
?>
<form method="POST"action="<?$PHP_SELF?>">
<input type="hidden" name="action"value="delete">
<select name="todelete">
<?
for($i=0; $i < $sizeof; $i++)
{$user = explode(":", $file_contents[$i]);
echo"<option value=\"$file_contents[$i]\">$user[0]</option>";}
?>
</select>
<br>
<input type="submit" value="delete user"><br>
</form>
<?
// start action routine for actual deletion or additon of new members
}
// start action routine for actual deletion or additon of new members
if ($_POST["action"]=="add") {
if($filehandle = fopen("$file_directory", "a")) {
$encrypted_pass = crypt($_POST["pwd"]);
fputs($filehandle,$_POST["user"]);
fputs($filehandle,":");
fputs($filehandle,$_POST["pwd"]);
fputs($filehandle,"\r\n");
fclose($filehandle);
echo"Successfully added",$_POST["user"],"to the file";}
else {echo($error);}
}
if ($_POST["action"]=="delete") {
if($filehandle = fopen("$file_directory", "w")) {
for($i=0; $i<$sizeof; $i++) {
if($file_contents[$i]==$_POST["todelete"])
{$flag = 1;}
else {fputs($filehandle,$file_contents[$i]);}
} //close for
fclose($filehandle);
if($flag) {echo"Successfully deleted",$_POST["todelete"],"from the file";}
else {echo"I didn't find", $_POST["todelete"],"to delete from file";}
}
else {echo"$error";}
}


?>

It gives me the error: I didn't find the user to delete.
Please help.I tested it on a local server called wamp5.

 

 (#914 2005-12-30 13:15:53) Post Reply

Gixboy
Need To Set


Enrolled: Nov 2005
Posts: 7
AP: 1

Alright guys, this, like a couple of my other assignments, is not exactly what the assignment asked for. I like taking the CONTENT of the lesson and applying it to something useful that we can all use. This time, I took the .htpasswd file and made it into a feedback form. It's much more dynamic than the assignment, and it puts into use EVERYTHING we've learned, including mail() functions, date() functions, rand() functions, cookies, regular functions, etc. It also has a new thing or two that you'll find extremely useful, which includes creating your own function and replacing thing. I don't know if people having trouble with this assignment will find my feedback script necessarilly useful, but you should still read it if you want to get some ideas.

The script is really broken down into three parts. On one page is the mod login which sets a cookie for the ENTIRE domain and expires when the window is closed. This way, you won't have to create a mod login on every page every time you need a moderator. I decided that this would be much more useful for that reason, plus it saves diskspace.

The next part is the feedback form. This is where you put the information you want to submit, and then submit it. The email address field is completely optional, but as you'll see on the final page, if you want to put an email address, you must put a real "looking" one. Also, sadly, because we're using .htpasswd files, you cannot use a colon in the textarea for anything. Emoticons, digital time, etc, are out of the question.

Finally, the juice. Because of the use of spaces, it's impossible to delete anything post with spaces because string names cannot include them. I don't know if that makes any sense, but the point is that we must give the "title" of each post a specific and unique number so that it can be deleted later on. That's what the rand function is for. Also, if the user hit enter to make new lines in the textarea, it will mess up your whole table unless you replace the carriage returns with an html break. I think the rest of the thing is self explanatory, but if anyone ever has any questions on any of this, I'm always open for asking.

My AIM is tnredsoxfan07, and when I'm on, I'll try to help you with whatever you need. The working url is at <a href="http://www.gixboy.com/">Gixboy.com</a>. I'd give you the address of the actual feedback form, but since it's in three parts, i'll just give you the domain. The feedback form can easilly be found though, it's the second option in the menu. The mod login can be found on the homepage right below the construction image.



#The Moderator Login

<?php
if($_POST['action']=="true") {
$filename="/home/gixboy/.htpasswds/members.txt";
$contents=file("$filename");
$sizeof=count($contents);
$user=$_POST['user'];
$pass=$_POST['pass'];
$htpasswd="$user:$pass\n";
for(
$i=0; $i<$sizeof; $i++) {
if(
$htpasswd==$contents[$i]) { $member="YES"; } }
if(
$member=="YES") {
setcookie("auth",$user);
header("Location: /refresher.php");
} }
?>

<HTML>
<BODY BGCOLOR="white" TEXT="navy" LINK="blue" VLINK="blue" ALINK="navy">
<?php
if($_COOKIE['auth']) {
echo(
"You are currently logged in as Moderator $_COOKIE[auth]. <a href=\"/logout.php\">Log Out</a>
<br><br>"
);
}
?>
<br>
<FORM method="POST" action="<? $PHP_SELF ?>">
<input type="hidden" name="action" value="true">
<center><table border="0">
<tr><td align="center" bgcolor="seagreen"><b><font color="black">
Moderator Login</font></b></td></tr>
<?php
if($_POST['action']=="true" && $member!="YES") {
print(
"<tr><td align=\"center\" bgcolor=\"red\"><font color=\"white\"><b>Invalid Username and/or
Password</b></font></td></tr>"
);
}
?>
<tr><td>
<table border="0" width="100%">
<tr><td valign="top" bgcolor="#EAFFEA">USERNAME:</td>
<td valign="top" bgcolor="#EAFFEA"><input type="text" name="user" size="20"></td></tr>
<tr><td valign="top" bgcolor="#EAFFEA">PASSWORD:</td>
<td valign="top" bgcolor="#EAFFEA"><input type="password" name="pass" size="20"></td></tr>
</table>
</tr></td>
<tr><td align="center" bgcolor="seagreen"><input type="submit" value="Login"></td></tr>
</table>
</FORM>
</BODY>
</HTML>





#The feedback form

<HTML>
<BODY BGCOLOR="white" TEXT="navy" LINK="blue" VLINK="blue" ALINK="navy">
<?php
if($_COOKIE['auth']) {
echo(
"You are currently logged in as Moderator $_COOKIE[auth]. <a href=\"/logout.php\">Log Out</a>
<br><br>"
);
}
?>
<br>
<FORM method="POST" action="feedback.php">
<input type="hidden" name="action" value="true">
<center><table border="0">
<tr><td align="center" bgcolor="seagreen"><b><font color="black">
Add Feedback Here</font></b></td></tr>
<tr><td>
<table border="0" width="100%">
<tr><td valign="top" bgcolor="#EAFFEA">Your name:</td>
<td valign="top" bgcolor="#EAFFEA"><input type="text" name="name" size="40"></td></tr>
<tr><td valign="top" bgcolor="#EAFFEA">Your email:</td>
<td valign="top" bgcolor="#EAFFEA"><input type="text" name="email" size="40"><br>
<i>Only give email if you want Gixboy.com to reply to your feedback</i></td></tr>
<tr><td valign="top" bgcolor="#EAFFEA">Feedback:<br>(Comments, Suggestions, Criticism, etc.)</td>
<td valign="top" bgcolor="#EAFFEA"><textarea name="comments" rows="7" cols=40" WRAP>
</textarea><br><i>Before submitting, make sure there are no colons (':')<br>
within your message. These nasty buggers will cut your<br>
comments short!</i></td></tr>
</table>
</tr></td>
<tr><td align="center" bgcolor="seagreen"><input type="submit" value="Submit"></td></tr>
</table>
</FORM>
</BODY>
</HTML>





# The feedback

<?php
$filename
="/home/gixboy/.htpasswds/email_form.txt";
if(
$_POST['action']=="true") {
if(
$_POST['email']==null || eregi("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)",$_POST['email'])) {
$name=$_POST['name'];
$email=$_POST['email'];
$comments=$_POST['comments'];
function
let_return($string)
{
$string = str_replace("\r\n", "<br />", $string);
return
$string;
}
$txt=let_return($comments);
$date=date("n/j/Y");
srand(microtime() * 10000000);
$num=rand(1,40000);
$fc=file($filename);
$count=count($fc);
for(
$i=0; $i<$count; $i++) {
$r=explode(":",$fc[$i]);
$t=$r[0];
if(
$num==$t) { $num=rand(1,40000); }
}
$contents1=(fopen("$filename","a"));
fwrite($contents1,"$num:$name:$date:$txt\n");
fclose($contents1);

$recipient="gixboy@gmail.com\n";
$subject="Feedback from Gixboy.com";
$body_of_email="$name has left the following feedback about Gixboy.com:

$comments

An automatic email has been sent to him/her, notifying that a moderator will
reply to him/her shortly."
;
$additional_headers="From: Gixboy.com";

$recipient2="$email\n";
$subject2="Thank you for your Feedback";
$body2="Thank you for your feedback at Gixboy.com. By submitting your email address,
you have requested that Gixboy.com could personally reply to your comments. We
enjoy the thoughts of all of our patrons, and will thus be in contact with you
(hopefully) within 24 hours. Thanks again for showing interest in our website.

DO NOT REPLY. This is an automatic email, and any replies will not be received.
If you wish to contact Gixboy.com sooner, use the email address provided below
the signature.

Gixboy.com - A Site That Does Something
gixboy@gmail.com"
;
$headers2="From: Gixboy.com";
} }
if(
$_POST['action4']=="true") {
$fc=file($filename);
$count=count($fc)-1;
$f=fopen($filename, "w");
for(
$i=0; $i<=$count; $i++) {
$k=explode(":",$fc[$i]);
$l=$k[0];
if(
$_POST[$l]==null) { fwrite($f,"$fc[$i]"); } }
fclose($f);
}
?>
<HTML>
<BODY BGCOLOR="white" TEXT="navy" LINK="blue" VLINK="blue" ALINK="navy">
<?php
if($_COOKIE['auth']) {
echo(
"You are currently logged in as Moderator $_COOKIE[auth]. <a href=\"/logout.php\">Log Out</a>
<br><br>"
);
}
?>

<center><b><font size="+1"><u>Gixboy.com's Feedback</u></font></b><br>
<i>Feedback is displayed for two months at a time,<br>then it is stored in seperate file.</i>
<br>
<?php
if($_POST['action']=="true") {
if(
$email!=null) {
if(
eregi("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)",$email)) {
if(
mail($recipient,$subject,$body_of_email,$additional_headers) && mail($recipient2,$subject2,$body2,$headers2))
{ print(
"<br><b><font size=\"+1\" color=\"red\">Your feedback has successfully been received via email by Gixboy.com</font></b><br>"); }
else { print(
"<br><b><font size=\"+1\" color=\"red\">There was an error in receiving your feedback via email by Gixboy.com.<br>
Please hit 'Back' and try again.</font></b><br>"
); } }
else { print(
"<br><b><font size=\"+1\" color=\"red\">You have provided an invalid email address.<br>
Please hit 'Back' and try again.</font></b><br>"
);
} } }
?>
<br>
<table border="0" width="80%" cellpadding="5">
<?php
if($_COOKIE['auth']) { ?>
<FORM method="POST" action="<? $PHP_SELF ?>">
<input type="hidden" name="action4" value="true">
<?php } ?>
<tr><td width="20%"></td><td align="right" width=75%"><a href="feedform.php">Leave Feedback</a>
</td>
<?php if($_COOKIE['auth']) { print("<td width=\"5%\"></td></tr>"); } ?>
</tr>
<tr><td align="center" bgcolor="seagreen"><b><font color="black">Name</font></b></td>
<td align="center" bgcolor="seagreen"><b><font color="black">Message</font></b></td>
<?php if($_COOKIE['auth']) { print("<td align=\"center\" bgcolor=\"seagreen\"><b>
<font color=\"black\">Del?</font></b></td></tr>"
); } ?>
</tr>
<?php
$contents3
=(file("$filename"));
$sizeof_fixed=(count($contents3)-1);
for(
$i=$sizeof_fixed; $i>=0; $i--) {
$feedback=explode(":",$contents3[$i]);
$txt3=stripslashes($feedback[1]);
$txt4=stripslashes($feedback[3]);
for(
$u=4; $u<=$sizeof_fixed; $u++) {
$txt4.=stripslashes($feedback[$u]);
}
?>
<tr><td valign="top" bgcolor="#EAFFEA"><? echo "<b>$txt3</b>"; ?><br>
<i><? echo "$feedback[2]"; ?></i></td>
<td valign="top" bgcolor="#EAFFEA"><? echo "$txt4"; ?></td>
<?php
if($_COOKIE['auth']) {
print(
"<td bgcolor=\"#EAFFEA\" align=\"center\">
<input type=\"checkbox\" name=\"$feedback[0]\" value=\"delete\"></td>"
); } ?>
</tr>
<?php
}
if(
$_COOKIE['auth']) { ?>
<tr><td></td><td></td><td><input type="submit" value="Delete"></td></tr></FORM> <?php } ?>
</table>
</BODY>
</HTML>


 

 (#982 2006-03-24 02:57:59) Post Reply

Russell
Need To Set


Enrolled: Mar 2006
Posts: 19
AP: 1

heres my lesson 10 advanced to-do assignment. once i got the basic assignment done this one wasnt too hard. working url is here http://www.bigtitsfinder.com/t...ng/lesson10.php
i added a few things just playing around with it and pounding it into my brain.


<center>
<?

//set a few variables to start it all off.

$path="/home/rlang/domains/bigtitsfinder.com/public_html/testing";
$error="Something went wrong. Check script and server path and try again.";
$file=file("$path/info.txt");
$size=count($file);
sort($file);

// if addform is true process added info and make sure email is a valid format.

if($addform=="true"){
if(
ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $youremail)){
if(
$filehandle=fopen("$path/info.txt","a")){
fputs($filehandle, "$yourname|$youremail\n");
fclose ($filehandle);
print(
"$yourname has been added.<br>Go back to the form area - <a href=\"$PHP_SELF\">click here</a>.<br>Or show all info added so-far - <a href=\"$PHP_SELF?showall=true\">click here</a>.");
}
}else{
print(
"Your email doesnt appear to be valid.<br>Please use your back button and try again.");
}
}

// elseif removeform is true remove the info from the file.

elseif($removeform=="true"){
if(
$filehandle=fopen("$path/info.txt","w")){
for(
$i=0; $i < $size; $i++){
if(
$file[$i] != $deleteme){
fputs($filehandle, "$file[$i]");
}
else{
$flag=1;
}
}
fclose($filehandle);
if(
$flag){
print(
"<b>$deleteme</b> has been removed.<br>Go back to the form area - <a href=\"$PHP_SELF\">click here</a>.<br>Or show all info added so-far - <a href=\"$PHP_SELF?showall=true\">click here</a>.");
}
}
}

// elseif show all info so far in a table to the browser.

elseif($showall=="true"){
if(
$filehandle=fopen("$path/info.txt","r")){
print(
"<table border=\"1\">");
for(
$i=0; $i<$size; $i++){
$info=explode("|", $file[$i]);
print(
"<tr><td>Name: $info[0]</td><td bgcolor=#cccccc>Email: $info[1]</td></tr>");
}
fclose($filehandle);
}
print(
"</table><br>go back to the form - <a href=\"$PHP_SELF\">click here</a>.");
}

// elseif add or remove form hasnt been submitted print ad and remove forms.

elseif(($addform!="true") OR ($removeform!="true")){
?>

<form method="post" action="<? $PHP_SELF ?>">
<input type="hidden" name="removeform" value="true">
<font size="4"><b>Add & Remove Names & E-mails Script</b></font><br>
Please select the info to be removed from the dropdown list below.<br>
<select name="deleteme"><br>
<?
for($i=0; $i<$size; $i++){
$info=explode("|", $file[$i]);
print(
"<option value=\"$file[$i]\">$info[0]</option>");
}
?>
</select>
<input type="submit" value="Delete User">
</form><br>

<form method="post" action="<? $PHP_SELF ?>">
<input type="hidden" name="addform" value="true">
Please enter your name and email below.<br>
Your Name: <input type="text" name="yourname" size="30"><br>
Your E-mail: <input type="text" name="youremail" size="30"><br>
<input type="submit" value="Submit"> &nbsp; &nbsp; <input type="reset" value="Reset">
</form>

<?
}
?>

</center>


 

 

View Previous Thread
Print this page Print This Page

View Next Thread

School Map:  Home / Enroll $ Student Records; Class  
$ News @ LIVE Tech Radio * Support/FAQ | Store

Advertising | Link To Us | Privacy 
Copyright 2000-2002 Script School Productions / KMR Enterprises 
No part of this website may be reproduced, copied and/or distributed in any medium 
without express written permission