Click to See Complete Forum and Search --> : [RESOLVED] Some help for a newbie.


ulyssesdraco
03-07-2006, 05:46 PM
Hey guys, I'm having a bit of trouble here. Im a total php newb, and all attempts to customize the following script have failed. Horribly. The script gives this form (http://thefunklounge.com/comicz/post.php). See how there's two sections. The top is for news posts and the bottom is for naming uploaded pictures. I only need the bottom part for naming comics, as I use something else for news posts. Now my dilemma. I looked at this big chunk-0-code, but I don't know how to isolate the part that gives me the comic name post thingy from the rest of the code so I can delete everything else I don't need. None of my friends know php and I couldn't track down the original author, so here I am. I hope someone can help me.

<?

// This is the first PHP work I've ever released publicly, so if
// you've got complaints or insults, please be gentle. ^_^
// As for some actual usage notes... I've made it so that you can
// enter anything into the post, and it'll work. That includes
// double- and single-quotation marks. You can also have fun with
// back-slashes and all that other crap. You don't need to insert
// HTML for <p>, because I've programmed the script to automatically
// turn any and all carriage returns into <p>'s for you. Have fun!
// Oh, and make sure you CHMOD your /news/ directory to allow for
// Public Writing. Don't worry, the public won't be writing to your
// news directory... this is just necessary for the post to work.
// ***********************************************


$myPassword = "chooseapassword";
$myComicPassword = "chooseapassword";
$myDirectory = "/your/news/directory/";
$posterName[0] = "yourname";
// $posterName[0] = "dude1";
// $posterName[1] = "dude2";
// $posterName[2] = "dude3";
$colorBackground = "#FFCC99";
$colorText = "#330066";

// *************************** THE WORKS
// DO NOT TOUCH!!
if(isset($_POST['comicTitle'])){
$comicTitle = $_POST['comicTitle'];
}
if(isset($_POST['comicPassword'])){
$comicPassword = $_POST['comicPassword'];
}
if(isset($_POST['comicTitlePosted'])){
$comicTitlePosted = $_POST['comicTitlePosted'];
}

if(isset($_POST['postTitle'])){
$postTitle = $_POST['postTitle'];
}
if(isset($_POST['password'])){
$password = $_POST['password'];
}
if(isset($_POST['postText'])){
$postText = $_POST['postText'];
}
if(isset($_POST['posted'])){
$posted = $_POST['posted'];
}
if(isset($_POST['poster'])){
$poster = $_POST['poster'];
}


function printPostForm()
{
foreach (array_keys($GLOBALS) as $i) {if(!isset(${$i})) global ${$i};} // Gather globals.

if( (@$password == null) and (@$posted == null) ) // If this is the first visit,
print(""); // Do nothing.
else if($password != $myPassword) // If the password variable is wrong,
print("<center>Incorrect password, please try again.</center>"); // Display error message.
else if($password == $myPassword) // If the password variable is right...
{
if($poster == "unchosen") // If the poster was not specified,
print("<center>Please specify a poster.</center>"); // Display error message.
else if($postTitle == null) // If the title was left blank,
print("<center>Please enter a title.</center>"); // Display error message.
else if($postText == null) // If the article was left blank,
print("<center>Please enter an article.</center>"); // Display error message.
else // If everything is in order...
{
$date = date("ymd-Hi-"); // Create the $date string.
$fileName = "$date$poster.php"; // Create the $fileName string.

$postTitle = str_replace("\\'", "'", $postTitle); // Fix any apostrophe problems in the title.

$postText = str_replace("\\'", "'", $postText); // Fix any apostrophe problems in the article.
$postText = str_replace("
", "\n<p>\n", $postText); // Turn all carriage returns to <p>.
// $postText = str_replace($postFind, $postReplace, $postText); // postReplacements.php mod... saving this for later!

$file = fopen("$myDirectory$fileName", "w+"); // Create the file.

fputs($file, '<?php
$postTitle = "');
fputs($file, "$postTitle");
fputs($file, '";
$postText = "

');
fputs($file, "$postText");
fputs($file, '

";
?>');

fclose($file); // Close the file.
}
}

if( (@$password != $myPassword) or (@$poster == "unchosen") or (@$postText == null) or ($postTitle == null) ) // If anything is wrong/blank...
{
@$postText = stripslashes($postText); // Remove all slashes from the article.
@$postTitle = stripslashes($postTitle); // Remove all slashes from the title.

print("<form method=\"post\" action=\"\">
<table border=\"0\" cellpadding=\"10\" cellspacing=\"0\">
<tr>
<td align=\"left\" width=\"33%\">
<br><select language=\"JavaScript\" size=\"1\" style=\"background-color: $colorBackground; font-size: 10 pt; font-family:

tahoma; color: $colorText;\" name=\"poster\">
<option value=\"unchosen\">Poster:\n");

for($i = 0; $i < sizeof($posterName); $i++) // Drop-down loop for the posters.
{
if(@$poster == $posterName[$i]) // Remember the poster if this page has been reloaded.
$selected = "selected"; // Reselect that poster.
else
$selected = "";

print(" <option value=\"$posterName[$i]\" $selected>$posterName[$i]\n");
}

print("
</select>
</td>
<td align=\"center\" width=\"33%\">
<b>Title of post:</b><br>
<input type=\"text\" name=\"postTitle\" value=\"$postTitle\" style=\"background-color: $colorBackground; font-size: 10 pt;

font-family: tahoma; color: $colorText;\"></input>
</td>
<td align=\"right\" width=\"33%\">
<b>Password:</b><br>
<input type=\"password\" name=\"password\" style=\"background-color: $colorBackground; font-size: 10 pt; font-family:

tahoma; color: $colorText;\"></input>
</td>
</tr>
<tr>
<td align=\"center\" colspan=\"3\">
<textarea rows=\"20\" cols=\"75\" name=\"postText\" style=\"background-color: $colorBackground; color:

$colorText;\">$postText</textarea><p>
<input type=\"submit\" name=\"posted\" value=\"Post It\" style=\"background-color: $colorBackground; font-size: 10 pt;

font-family: tahoma; color: $colorText\"></input>
</td>
</tr>
</table>
</form>");
}
else if( ($password != null) and ($password == $myPassword) and ($poster != "unchosen") and ($postText != null) and ($postTitle !=null) )
print("<center>Article has been posted.</center>");

// *****************************************************************

if( (@$comicPassword == null) and (@$comicTitlePosted == null) ) // If this is the first visit,
print("<p><hr>"); // Do nothing.
else if($comicPassword != $myComicPassword) // If the password variable is wrong,
print("<p><hr><p><center>Incorrect password, please try again.</center>"); // Display error message.
else if($comicPassword == $myComicPassword) // If the password variable is right...
{
$comicTitle = str_replace("\\'", "'", $comicTitle); // Fix any apostrophe problems in the title.

include("comicConfig.php");
include($fileTitles);

$totalComicsNew = $totalComics + 1;

$file = fopen($fileTitles,"r+");
fseek($file, 4);
fputs($file, "\n" . '$totalComics = '. "$totalComicsNew;\n");
fseek($file, -3, SEEK_END);
fputs($file, '$titleStrip[' . "$totalComicsNew] = \"$comicTitle\";\n\n?>");

fclose($file); // Close the file.
}

if( (@$comicPassword != $myComicPassword) or ($comicTitle == null) ) // If anything is wrong/blank...
{
@$comicTitle = stripslashes($comicTitle); // Remove all slashes from the title.

print("<p><form method=\"post\" action=\"\">
<table border=\"0\" cellpadding=\"10\" cellspacing=\"0\">
<tr>
<td align=\"left\" width=\"33%\">
<b>Title of comic:</b><br>
<input type=\"text\" name=\"comicTitle\" value=\"$comicTitle\" style=\"background-color: $colorBackground; font-size: 10

pt; font-family: tahoma; color: $colorText;\"></input>
</td>
<td align=\"center\" width=\"33%\">
<b>Password:</b><br>
<input type=\"password\" name=\"comicPassword\" style=\"background-color: $colorBackground; font-size: 10 pt; font-family:

tahoma; color: $colorText;\"></input>
</td>
<td align=\"right\" width=\"33%\">
<input type=\"submit\" name=\"comicTitlePosted\" value=\"Post It\" style=\"background-color: $colorBackground; font-size:

10 pt; font-family: tahoma; color: $colorText\"></input>
</td>
</tr>
</table>
</form>");
}
else if( ($comicPassword != null) and ($comicPassword == $myComicPassword) and ($comicTitle !=null) )
print("<center>Comic title has been posted.</center>");
}

?>

welsh
03-07-2006, 08:04 PM
this is the chunk that gives the first group.
print("
</select>
</td>
<td align=\"center\" width=\"33%\">
<b>Title of post:</b><br>
<input type=\"text\" name=\"postTitle\" value=\"$postTitle\" style=\"background-color: $colorBackground; font-size: 10 pt;

font-family: tahoma; color: $colorText;\"></input>
</td>
<td align=\"right\" width=\"33%\">
<b>Password:</b><br>
<input type=\"password\" name=\"password\" style=\"background-color: $colorBackground; font-size: 10 pt; font-family:

tahoma; color: $colorText;\"></input>
</td>
</tr>
<tr>
<td align=\"center\" colspan=\"3\">
<textarea rows=\"20\" cols=\"75\" name=\"postText\" style=\"background-color: $colorBackground; color:

$colorText;\">$postText</textarea><p>
<input type=\"submit\" name=\"posted\" value=\"Post It\" style=\"background-color: $colorBackground; font-size: 10 pt;

font-family: tahoma; color: $colorText\"></input>
</td>
</tr>
</table>
</form>");

ulyssesdraco
03-07-2006, 09:41 PM
So then I just delete that?

ulyssesdraco
03-08-2006, 02:53 PM
Update:

I removed the code for the first box and tried it. All I get is a blank page. No errors though.

Update 2:

Got it to work through trial and error. Welsh pointed me in the right direction. I ended up deleting more than half of the code. Many thanks.