Jump to content

[SOLVED] Won't pick up variable


jcbarr

Recommended Posts

Any ideas why this script isn't picking up the $editdraft variable that is being sent via the form at the bottom of the script?

 

<html>
<head>
<title>Draft Admin</title>
</head>
<body><BR><BR><BR><BR><BR>

<center>
<a href=admin.php?CREATE=Y>CREATE DRAFT FILE</a>
<P>
<a href=admin.php?EDIT=Y>EDIT DRAFT FILE</a>
<P>
<?php

//Gather Variables
$create = $_GET['CREATE'];
$edit = $_GET['EDIT'];
$make = $_POST['make'];
$year = $_POST['year'];
$type = $_POST['type'];
$draft = $_POST['draft'];
$editdraft = $_POST['editdraft'];

echo $editdraft;

//Create Draft File Form
if (!empty($create)){
echo <<<END
<b><h2>CREATE DRAFT</h2></b>
<form method="post" action="admin.php">
<input type="hidden" name="make" value="Y">
<input type="text" name="year" value="Type Year Here">
<select name="type"><option value="FA">Free Agent</option>
<option value="AM">Amateur</option>
</select>
<input type="submit" value="Create Draft">

</form>
END;
}

//Create TXT File For Draft
if ($make=="Y"){
$filename = "$year$type";
$ext = ".txt";
fopen("drafts/$filename$ext", "w+");
echo "$filename has been created. Click <a href=admin.php>here</a> to refresh page.";
}


//Make Select Edit Form
if ($edit=="Y"){ ?>
<B><h2>SELECT DRAFT FILE TO EDIT</b></h2> <form name="form1" method="post" action="admin.php"><select name=draft onchange=form1.submit()><option value=''></option>
<?php
$dir = "drafts";
$dh  = opendir($dir);
while (false !== ($filename = readdir($dh))) {
   $files[] = $filename;
}

sort($files);

foreach ($files as $drafts){
if ($drafts !== '.' && $drafts !== '..'){
 	$drafts = substr($drafts, 0, 6);
	echo "<option value='$drafts'>$drafts</option>";
}
}
?>
</select>
</form>


<?php	
}

//Make Edit Form
if (!empty($draft)){
$ext = ".txt";
$filename = "$draft$ext";
$text = file_get_contents("drafts/$filename");
echo <<<END
<form name='form2' method='post' action='admin.php'>
<input type="hidden" name="editdraft" value="$filename">
<TEXTAREA NAME="edit" ROWS=50 COLS=50>$text</TEXTAREA>
<BR>
<INPUT TYPE="reset">
<INPUT TYPE="submit" NAME="submit" VALUE="Submit">
</FORM>
END;
}


//Write To Draft File
if (!empty($editdraft)){
$handle = fopen("$editdraft", "w+");
fwrite($handle, $edit);
fclose($handle);
echo "$editdraft has been edited. Click <a href=admin.php>HERE</a> to refresh page.";
}

?>
</center>

</body>
</html>

Link to comment
Share on other sites


<?php	
}

//Make Edit Form
if (!empty($draft)){
$ext = ".txt";
$filename = "$draft$ext";
$text = file_get_contents("drafts/$filename");

echo "<form name="form2" method='post' action='admin.php'>";
echo "<input type="hidden" name="editdraft" value="$filename">";
echo "<TEXTAREA NAME="edit" ROWS=50 COLS=50>$text</TEXTAREA>";
echo "<BR>";
echo "<INPUT TYPE="reset">";
echo "<INPUT TYPE="submit" NAME="submit" VALUE="Submit">";
echo "</FORM>";

}


//Write To Draft File
if (!empty($editdraft)){
$handle = fopen("$editdraft", "w+");
fwrite($handle, $edit);
fclose($handle);
echo "$editdraft has been edited. Click <a href=admin.php>HERE</a> to refresh page.";
}

?>

 

You need to sort out the quotes.

 

monk.e.boy

Link to comment
Share on other sites

I would check the filename, chances are that is where the error is., I never used the <<<END and END; Try it this way:

 

echo '<form name="form2" method="post" action="admin.php">
<input type="hidden" name="editdraft" value="'.$filename.'">
<TEXTAREA NAME="edit" ROWS=50 COLS=50>$text</TEXTAREA>
<BR>
<INPUT TYPE="reset">
<INPUT TYPE="submit" NAME="submit" VALUE="Submit">
</FORM>';

 

see what happens.

Link to comment
Share on other sites

That isn't where the problem lies, the file is opening fine and populating the text area, so I know that the filename is right, when I view source it even shows up in the input tag, but it won't pass it to the script when the form is submitted.

Link to comment
Share on other sites

Here is the deal if anyone cares. Apparently it had to do with my browser settings at home. My browser was apparently not loading the page again it was just using a cached version or something like that.

 

I get to work and the thing works without a hitch, so I guess everything is okay now.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.