VaultNetwork.netVault Network Boards
Author Topic: Ok board for PHP/SQL help? Looking to make first/previous/next/last buttons [Locked]
Phases_OgMaxim  1 star
Posts: 52
Registered: 2002-7-16 16:32:23
What up Raiz, you still around? Gearing up to get my next little project started. I don't imagine it to be something I can't figure out, but I might have some questions for ya. Basically here's what's to come:

http://superstickphase.com/notify.php
http://superstickphase.com/contact.php

For the first one, notifications.

What I want to have happen (what seems best anyway) is when people fill out the form to get notifications and hit submit.. have php do the following:
- See what they chose to fill in. Whatever they left blank use a dash (-) for the variable.
- Check that the email is in fact an email (or at least something@something.something)
- Append that data into an existing file on my server. The file entries look just like this:

nickname|first|last|email|

I don't plan to use nicknames, so probably just use a dash for that. So I imagine say, five sign-ups, the file could look something like this

-|-|-|someone@gmail.com|
-|-|-|someoneelse@yahoo.com|
-|Deirdre|-|deirdres@email.com|
-|-|Bob|Bobster|bobbobster@comcast.net|
-|-|-|raiztlin@youknowyouwanttosignuponmysite.com|

this file isn't in my web dir so I guess I'll have to give apache rights to it or make a symlink to it but I'm not too worried about that.

As for the second part of notify.. removing an email. I think automating that might not be worth the trouble it would probably be to get php to read the whole file and pull out the line with the input'd email. (or would that be easy?) So I was figuring I'd just have that append to some other file that'd I'd just periodically check and manually remove the people.

((SEE EDIT BELOW)) The second page, the contact me. I'd like to have my mail server email that to my mail account, but I'm not sure how simple that would be. I bet it'd be easier to have it toss that into a sql database and make a page I use to view it all. Like a little mini webmail page. That shouldn't be hard. I'll just have to brush (way) up on my mysql skillz.

So. There's my plan. Whatcha think?

Edit: Ok! Well the contact me was easy! Following this for guidance: http://www.visn.co.uk/form-mail.html and doing a little tweaking, and works pretty well. I've got it emailing to two accounts, and also making sure there is something actually in the note field before it accepts the submission. Rockin'! However.. it puts slashes before quotes and apostrophes. It sorta sucks but I can certainly live with that. It's functional and that's all I really care about. So, onto the notification list...

Edit 2: Alright, have the notify page sending the add form variables to one php page for processing, and the remove part sending to a second php page for processing. I have both set to reject submission with no email filled in. Working on the submitting for notifies, this is what I've got that isn't ((EDIT: is now!) working:

$first = $_REQUEST['first'];
$last = $_REQUEST['last'];
$email = $_REQUEST['email'];
$entry = "-" . "|" . "$first" . "$last" . "|" . "$email" . "|" . "\n";
$fp = fopen('/path/to/file', 'a';
fwrite($fp,$entry);
fclose($fp);

Man I rock.
I'd like though, for it (just like the contact me form) to check that it's at least in correct email format before accepting it, and I'd also be cool with it checking for duplicate addresses.
But it works! On to auto removal..

Edit 3..how would I do this? file_get_contents.. then remove the line with the address, then file_put_contents?

Alright no more edits tonight I promise! Imma get some sleep right quick.

 

-----signature-----
Every forum should have a Phases.
Bringing SSP back to life at http://www.superstickphase.com !
Retired AC/AC2 - Phases Og'Maxim - Leafcull
Phases_OgMaxim  1 star
Posts: 52
Registered: 2002-7-16 16:32:23
Morning. Ok here's the short version of where I still stand on my last post's progress. Will update it as things change.

-Would like my notification sign up form to check email addresses for syntax. (check!)
-Would like my contact me form to check email addresses for syntax..That field is optional on this form. (check!)
-Wouldn't mind if I could make it so it doesn't put slashes in the data I collect before apostrophes and quotes. (check!)
-Remove from notifications form still not functional. Would like it to remove from the file automatically. (check!)
-Would like my notification sign up and removal form to check for existing email address when submitted and let user know.

Edit: ..alright I've done pretty good on my own and made pretty good time . But, the last two ^^ I think I might need help with..
Edit: Working on auto removal in mailing list. I can get php to open and read the file, put it into a string and print it out.. and replace the email address but, I need it to replace the email address and everything touching it (so the whole line will be replaced..with a space). Here's what I'm toying with at the moment:
Edit: Got it. It just replaces the address with a space, my address book shows the entry but iwth no address, and when I go to compose and email the list those entries get ignored. Good enough!

Now all that's left of this part of the project is to check for existing and honestly I'm not that worried about it until I actually start getting some sign ups. Dupe's are ignored on the email out anyway, and all instances of an email address are removed when asked too so.. no change in functionality, just to keep it clean.

.. I debate a comment system..

 

-----signature-----
Every forum should have a Phases.
Bringing SSP back to life at http://www.superstickphase.com !
Retired AC/AC2 - Phases Og'Maxim - Leafcull
Raiztlin  2 stars
Title: Dick Tracy
Posts: 397
Registered: 2002-1-23 08:10:37
Looks to me like you're doing good


I don't understand why you're using textfiles to save your userdata though, would be a lot easyer to put it all in a database


I'd just put it all in a table, that way you can pull the exact data you want to, whenever you want to. Making emailing your users super easy (esp with the built in php mail() function.

 

-----signature-----
I has a flavor!
CC always welcome.
Phases_OgMaxim  1 star
Posts: 52
Registered: 2002-7-16 16:32:23
Well, because I use an existing front end for the email.. so I'm just using the address book file that it uses by default. I have a "newcomic" account set up so any address that makes it into it's address book is solely for this purpose. It wouldn't be a cookie cutter email either, it's going to tell of the new comics then also any news that there may happen to be.



Edit: and how dare you disappear when I need you. Don't you know you're supposed to be on standby awaiting requests from me at all times?

 

-----signature-----
Every forum should have a Phases.
Bringing SSP back to life at http://www.superstickphase.com !
Retired AC/AC2 - Phases Og'Maxim - Leafcull
Raiztlin  2 stars
Title: Dick Tracy
Posts: 397
Registered: 2002-1-23 08:10:37
well, I usually just browse this board once a day really :]


You can feel free to add me to your msn, my addy is kellendil@gmail.com

 

-----signature-----
I has a flavor!
CC always welcome.
Phases_OgMaxim  1 star
Posts: 52
Registered: 2002-7-16 16:32:23
Only use yahoo, and that's only when I'm at home, and that gchat thing I use here at work too. Perhaps if I have a pressing matter I can email that addy and let ya know there's something here, then at same time that'll put you on the gchat contact list?

Anyway, check this out! I'm proud of me. I've started a new project on the site because I got a wild hair and realized I could do it, so I am. It's real sloppy at the moment but getting more and more functional.

I made a manage (password protected area) of the site with the following so far:

---------------------------------------------------------
manage.php (this just the php, stripped out formatting):

<!-- File Upload, This is on all the pages in the manage area, and submits to a uploader.php page for processing. Works well! -->

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
File: <input name="uploadedfile" type="file" size="10"/><br />
Directory: <input type="radio" name="dir" value="images">Images
<input type="radio" name="dir" value="archive">Archive<br>
<input type="submit" value="Upload" />
</form>

<!-- End File upload -->

<!-- check for need to edit file with data sent back from fileedit.php which I'll show ya in a sec.-->
<?php
if (isset($_POST['filetoedit'])) {
$filetoedit = $_POST['filetoedit'];
$newcontent = $_POST['newcontent'];
$newcontent2 = stripslashes($newcontent);
$fp = fopen($filetoedit, 'w+';
fwrite($fp, $newcontent2);
fclose($fp);
}
?>
<!--- End check for need to edit file -->

<!--- Display contents of root dir and the main 2 other directories I edit files in -->
<?php
$dir = '/var/www/';
$files = scandir($dir);
echo "<b>Files in ".$dir.":</b><br>";
for($i=0; $i < count($files); $i++) {
echo "<a href='editfile.php?id={$dir}{$files[$i]}'>";
echo "$files[$i]<br>";
echo "</a>";
}
?>

<?php
$dir2 = '/var/www/files/';
$files2 = scandir($dir2);
echo "<b>Files in ".$dir2.":</b><br>";
for($i=0; $i < count($files2); $i++) {
echo "<a href='editfile.php?id={$dir2}{$files2[$i]}'>";
echo "$files2[$i]<br>";
echo "</a>";
}
?>

<?php
$dir3 = '/var/www/manage/';
$files3 = scandir($dir3);
echo "<b>Files in ".$dir3.":</b><br>";
for($i=0; $i < count($files3); $i++) {
echo "<a href='editfile.php?id={$dir3}{$files3[$i]}'>";
echo "$files3[$i]<br>";
echo "</a>";
}
?>
<!-- End display contents of 3 main directories -->
-------------------------------------------------------

As you can see those three main directory contents are clickable and go to a edit.php page that puts all the contents into a textarea, and lets me change it around, hit edit, and then from there it's sent back to this page for processing.

Here are other pages' php content in case you're interested:

-----------------------------------------------------
uploader.php:

<?php
if (($HTTP_POST_VARS[dir])==("archive") {
$target_path = "/var/www/archive/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "<center>The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded. Back to <a href='manage.php'>Manage.</a></center>";
}

else {
echo "There was an error uploading the file, please try again!";
}
}

elseif (($HTTP_POST_VARS[dir])==("images") {
$target_path = "/var/www/images/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "<center>The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded. Back to <a href='manage.php'>Manage.</a></center>";
} else {
echo "There was an error uploading the file, please try again!";
}
}

else {
echo "<center>Please select an upload directory.</center>";
}
----------------------------------------------------

------------------------------------------------------
and finally editfile.php that takes the clicked file from the listing on manage.php and lets you edit contents:

<?php
if (isset($_GET['id'])) {
$file = $_GET['id'];
$fp = fopen($file, 'r+';
$content = fread($fp, filesize($file));
fclose($fp);

echo '<center>
<form action="manage.php" method="post">
<textarea cols="125" rows="50" name="newcontent">'.$content.'</textarea><br>
<input type="hidden" name="filetoedit" value="'.$file.'"><br>
<input type="submit" value="edit">
</form></center>';
}
?>
-------------------------------

So that's tight, but a problem I'm having is when I actually click to edit the edit.php file, it gives me all the code up to the '.'$content.'

..in the text area, and then ends it and shows the edit button and then AFTER that, shows

';}?>

.. then puts another edit button. So I guess it's processing what it's supposed to be showing me. So that's sorta weird.

Soon as I get that figured out I'm going to have some cleaning up to do.

-I'd like it to NOT show the . and .. on the dir listings,
-I'd like the folders to either not show, or when clicked show the files within. At the moment they go to edit.php and fail with unopenable stream.
-I'm going to make edit/delete/copy/newfolder/newfile buttons

 

-----signature-----
Every forum should have a Phases.
Bringing SSP back to life at http://www.superstickphase.com !
Retired AC/AC2 - Phases Og'Maxim - Leafcull
Phases_OgMaxim  1 star
Posts: 52
Registered: 2002-7-16 16:32:23
This is killing me. When it makes the text area to echo $content into for the edit.php page on the edit.php page, it makes the text area to put the content in fine, and does spit out $content up to that point. But when it's trying to echo the closing </textarea> tag within $content, the site actually works the tag instead of just prints it inside the textarea.

If I just remove </textarea> altogether it works, but then it breaks the rest of the page on down.

Any way past that?

 

-----signature-----
Every forum should have a Phases.
Bringing SSP back to life at http://www.superstickphase.com !
Retired AC/AC2 - Phases Og'Maxim - Leafcull
Raiztlin  2 stars
Title: Dick Tracy
Posts: 397
Registered: 2002-1-23 08:10:37
Good job so far :]


As for the textarea that's pretty damn weird, I'm sure there's just something we're both missing that's causing it


You could see if it is the single quotes that does it:

echo "<center>"

"<form action=\"manage.php\" method=\"post\">

<textarea cols=\"125\" rows=\"50\" name=\"newcontent\">".$content."</textarea><br>

<input type=\"hidden\" name=\"filetoedit\" value=\"".$file."\"><br>

<input type=\"submit\" value=\"edit\">

</form></center>";

}


if not that, try splitting it up into more then one echo statement.


As for showing the . and .. in the dirs, those are just the two first items in the array created, you should be able to strip those without much difficulty.


"-I'd like the folders to either not show, or when clicked show the files within. At the moment they go to edit.php and fail with unopenable stream."

Not sure I understand what you mean here.

 

-----signature-----
I has a flavor!
CC always welcome.
Phases_OgMaxim  1 star
Posts: 52
Registered: 2002-7-16 16:32:23
[Edit - see bottom reply]

Ah thanks for the reply! I hope you can help me.

I've tried it with double quotes, singles, multiple echo statements.. I can't get it to NOT work the </textarea> !! It's driving me nuts.

As for stripping . and .. - I agree it should be easy but I want to get past this hurdle first.
As for the folder thing.. At the moment it lists all files and folders in the directory. just names. so like:

file.php
file2.php
folder
file3.php
folder2

Makes each one clickable to editfiles.php?id=[whateveryouclicked]
So if I click file.php, it goes to editfiles.php?id=file.php

When it gets to editfiles.php it pulls the id and makes it a variable:
$variable = file.php

Then in it freads the conents of $variable and puts it into the text box.

If it's a folder I click, say 'folder' in the above example, it sends it to editfiles.php?id=folder
sets it: variabe = folder
then trys to fread folder, which gives me a 'stream failed, may be a folder' error message.

.... as for the </textarea>.... (here come some edits)

Edit: I've tried the following:

echo '<center>
<form action="manage.php" method="post">
<textarea cols="125" rows="50" name="newcontent">'.$content.'</textarea><br>
<input type="hidden" name="filetoedit" value="'.$file.'"><br>
<input type="submit" value="edit">
</form></center>';

and

echo "<center>
<form action='manage.php' method='post'>
<textarea cols='125' rows='50' name='newcontent'>".$content."</textarea><br>
<input type='hidden' name='filetoedit' value='".$file."'><br>
<input type='submit' value='edit'>
</form></center>";

and

echo '<center>
<form action="manage.php" method="post">
<textarea cols="125" rows="50" name="newcontent">';
echo $content;
echo '</textarea><br>
<input type="hidden" name="filetoedit" value="'.$file.'"><br>
<input type="submit" value="edit">
</form></center>''

and more... all same result.

edit 2: your suggestion to try:

echo "<center>
<form action=\"manage.php\" method=\"post\">
<textarea cols=\"125\" rows=\"50\" name=\"newcontent\">".$content."</textarea><br>
<input type=\"hidden\" name=\"filetoedit\" value=\"".$file."\"><br>
<input type=\"submit\" value=\"edit\">
</form></center>";

.. same(ish) result. Still prints all the way up to >".$content." ..then the the textarea closes with </textarea>

 

-----signature-----
Every forum should have a Phases.
Bringing SSP back to life at http://www.superstickphase.com !
Retired AC/AC2 - Phases Og'Maxim - Leafcull
Phases_OgMaxim  1 star
Posts: 52
Registered: 2002-7-16 16:32:23
[EDIT: see bottom reply]

I may or may not be onto something:

$replace = '<textarea>';
$newcontent = str_replace("</textarea>", $replace, $content);
echo '<center>
<form action="manage.php" method="post">
<textarea cols="125" rows="50" name="newcontent">'.$newcontent.'</textarea><br>
<input type="hidden" name="filetoedit" value="'.$file.'"><br>
<input type="submit" value="edit">
</form></center>';

It works and doesn't break the page, however the $newcontent displayed also does the replace:

$replace = '</textarea>';
$newcontent = str_replace("</textarea>", $replace, $content);
echo '<center>
<form action="manage.php" method="post">
<textarea cols="125" rows="50" name="newcontent">'.$newcontent.'</textarea><br>
<input type="hidden" name="filetoedit" value="'.$file.'"><br>
<input type="submit" value="edit">
</form></center>';

... so that if I then saved the page, it would re-break it.
Thoughts?

 

-----signature-----
Every forum should have a Phases.
Bringing SSP back to life at http://www.superstickphase.com !
Retired AC/AC2 - Phases Og'Maxim - Leafcull

VaultNetwork.net is an independently operated community forum and is not affiliated with, endorsed by, or technically based on IGN, GameSpy, FilePlanet, GameStats, or the former IGN/GameSpy Vault Network.
References to VaultNetwork.net mean this site/domain. VNBoards-style presentation is a visual homage only. By using this site, you agree to the forum rules.